Back

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

I have a situation when I click on the button opens the new browser window with search results.

Is there any way to connect and focus to a newly opened browser windows?

And work with it, then return back to the original(first) window.

1 Answer

0 votes
by (50.2k points)

Switching of windows can be done by following this

// get the current window handle

 String parentHandle = driver.getWindowHandle();

 for (String handle: driver.getWindowHandles()) {

     if (!parentHandle.equals(handle))

         driver.switchTo().window(handle);

 }

It works and there is no wrong using this.

Further queries refer:

 /selenium-webdriver-automatic-switching-between-browser-windows-using-guice-method-interceptor/ 

Browse Categories

...