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

0 like 0 dislike
944 views
by The go-to Tester (473 points)
retagged by
Currently i have button in iframe. If i click on this button manually then next window opens in next tab of current window.

But in case of selenium auto script, if script click on that button then next window opening in new browser instead of next tab of current browser.

1 Answer

0 like 0 dislike
by
selected by
 
Best answer

That's how selenium behaves. You will have to switch to the new window and do your validation.

To do that,

You can first get current window handle using

String currentWindowHandle = driver.getCurrentWindowHandle();

Then,

You can get all window handles. This will give  you handles of all open windows.

List<String> windowHandles = driver.getWindowHandles();

Next you can iterate through windowHandles and get window handle of newly opened window handle. Switch to newly opened window and work on it.

for(String windowHandle : windowHandles){

if(!currentWindowHandle.equals(windowHandle))

driver.switchTo().window(windowHandle);

}

Hope that works.

by
Thanks. I got answer.


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

...