Java Selenium: open new tab


Danny Cobb

So I URLwant to browse this link in a new tab, which is not clickable, so when I click this button, nothing happens and will not work (even if not manually):

    WebElement hrefLink;
        actions.keyDown(Keys.SHIFT).click(hrefLink).keyUp(Keys.SHIFT).build().perform();

        // Handle windows change.
ArrayList<String> tabs = new ArrayList<String>(Browser.driver().getWindowHandles());

     // Switch to the new tab.
     driver.switchTo().window(tabs.get(1));

So I try this approach:

driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");

And no new tabs open.

Any suggestions?

renew

Here is my url:https://bitly.com/

Rotislav Balmakov

You can start with the following workarounds:

void openNewTab(WebDriver driver) {
    ((JavascriptExecutor) driver).executeScript("window.open('https://google.com');"); 
}

And here is similar to your question. Might be useful ;)

Related


Java Selenium: open new tab

Danny Cobb So I URLwant to browse this link in a new tab, which is not clickable, so when I click this button, nothing happens and will not work (even if not manually): WebElement hrefLink; actions.keyDown(Keys.SHIFT).click(hrefLink).keyUp(Keys.SHI

Unable to open new tab with Selenium

Kay I'm trying to open each listing from eBay for scraping. My goal is to open each eBay listing in a "for loop" so that I can grab the data for each listing. Unfortunately, I get an error message: selenium.common.exceptions.JavascriptException: Message: javas

How to open a link in a new tab in a menu using Selenium in Java

Ashish Savaliya I am trying to open a link in a new Tab in Selenium Java, but the first time only one link opens, but when opening the second link the For Loop is giving an error, can anyone help me with this. Here is my code. public class Link_Open_In_New_Tab

How to open a link in a new tab in a menu using Selenium in Java

Ashish Savaliya I am trying to open a link in a new Tab in Selenium Java, but the first time only one link opens, but when opening the second link the For Loop is giving an error, can anyone help me with this. Here is my code. public class Link_Open_In_New_Tab

Open Web Selenium + Python in a new tab

Robert W. Hunter: So I am trying to open the website on a new tab inside WebDriver. I want to do this because it takes about 3.5 seconds to open a new WebDriver for each website using PhantomJS, so I want to improve the speed... I'm using a multiprocess python

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and you need to verify the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and con

How to open new tab with Selenium WebDriver?

Bhakti Shah How to open new tabs in existing Firefox browser using Selenium WebDriver (aka Selenium 2)? long gar ten champani The following code will open the link in a new tab. String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN); driver.find

Open Web Selenium + Python in a new tab

Robert W. Hunter: So I am trying to open the website on a new tab inside WebDriver. I want to do this because it takes about 3.5 seconds to open a new WebDriver for each website using PhantomJS, so I want to improve the speed... I'm using a multiprocess python

Open Web Selenium + Python in a new tab

Robert Hunt So I am trying to open the website on a new tab inside WebDriver. I want to do this because it takes about 3.5 seconds to open a new WebDriver for each website using PhantomJS, so I want to improve the speed... I'm using a multiprocess python scrip

Python + Selenium WebDriver: open URL in new tab

Luke Van Zweiden I have a text document with a URL per line. I want each URL to open in a new tab. Here is what I have so far: tabs = 0 f = open('links.txt', 'r', encoding='utf-8') for line in f: url = line driver.execute_script("window.open(url, 'new_

How to open new tab with Selenium WebDriver?

Bhakti Shah How to open new tabs in existing Firefox browser using Selenium WebDriver (aka Selenium 2)? long gar ten champani The following code will open the link in a new tab. String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN); driver.find

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and you need to verify the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and con

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and you need to verify the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and con

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act

Open Web Selenium + Python in a new tab

Robert W. Hunter: So I am trying to open the website on a new tab inside WebDriver. I want to do this because it takes about 3.5 seconds to open a new WebDriver for each website using PhantomJS, so I want to improve the speed... I'm using a multiprocess python

How to command click (open in new tab) in selenium

Joey I have an array of selenium.webdriver.remote.webelement.WebElements . In order to loop through the elements and keep the session, I need to open each element in a new tab, extract the data, and then close the tab. I see that there is a way to open a new t

How to open new tab using selenium python?

Good face I'm trying to make a program that can open multiple websites, but I can't press control-t. I tried multiple solutions but couldn't find one that worked. When I execute the keydown method, I get an error message webdriver has no attribute key_down Wh

Open element (url) in new tab in Python Selenium

ASP Goal: Need to open a webpage, find urls by class, and open each url in a new tab in chrome What I have tried: from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys driver = webdriver.Chro

How to open new tab with Selenium WebDriver?

Bhakti Shah How to open new tabs in existing Firefox browser using Selenium WebDriver (aka Selenium 2)? long gar ten champani The following code will open the link in a new tab. String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN); driver.find

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and need to validate the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and conti

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act

Python + Selenium WebDriver: open URL in new tab

Luke Van Zweiden I have a text document with a URL per line. I want each URL to open in a new tab. Here is what I have so far: tabs = 0 f = open('links.txt', 'r', encoding='utf-8') for line in f: url = line driver.execute_script("window.open(url, 'new_

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act