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.
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); }
// 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/