Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I'm using Selenium and Firefox.

I have a link on a page (say linkA) that opens a new page in a new tab. The new tab is displayed when linkA is clicked. I then want to interact with the new page.

Here is my selenium script:

  • click linkA
  • pause 5000
  • selectWindow Title
  • click linkB (note: linkB is on the new page)

Selenium cannot identify the new tab. It reports:

[warn] Link has target '_blank', which is not supported in Selenium! Randomizing target to be: selenium_blank24003

Is there any way to tell Selenium to interact with the displayed tab?

1 Answer

0 votes
by (62.9k points)

Use this Code:
 


public void newtab(){ 
System.setProperty("webdriver.chrome.driver", "E:\\eclipse\\chromeDriver.exe"); 
WebDriver driver = new ChromeDriver();
driver.get("https://intellipaat.com"); 
driver.findElement(By.className("tryitbtn")).click();
new Actions(driver).sendKeys(driver.findElement(By.tagName("html")), Keys.CONTROL).sendKeys(driver.findElement(By.tagName("html")), Keys.NUMPAD2).build().perform(); 
// In keyboard we will press //ctrl+1 for 1st tab //ctrl+2 for 2nd tab //ctrl+3 for 3rd tab. //Same action is written in the //above code. 

}

Browse Categories

...