change focus to a new popup tab in Selenium

Solved 1 Answers 751 Views Selenium
0 1

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

Best answer

you will have to use driver switch to.

You can switch between windows as below:

//Store the current window handle
String winHandleBefore = driver.getWindowHandle();

//Perform the click operation that opens new window

//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){

// Perform the actions on new window

//Close the new window, if that window no more required

//Switch back to original browser (first window)


//continue with original browser (first window)
answered by (327 points)
selected by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

We have resolved 1.2k+ Software Testing queries!

Top Contributors