Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
5.5k views
in Selenium by
recategorized by

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 like 0 dislike
by The go-to Tester (327 points)
selected by
 
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()){
    driver.switchTo().window(winHandle);
}

// Perform the actions on new window

//Close the new window, if that window no more required
driver.close();

//Switch back to original browser (first window)

driver.switchTo().window(winHandleBefore);

//continue with original browser (first window)


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...