Created
May 13, 2015 13:26
-
-
Save ECiurleo/7190153d313474b6dbec to your computer and use it in GitHub Desktop.
Selenium Window Switch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String parentHandle = driver.getWindowHandle(); // get the current window handle | |
driver.findElement(By.xpath("//*[@id='someXpath']")).click(); // click some link that opens a new window | |
for (String winHandle : driver.getWindowHandles()) { | |
driver.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window) | |
} | |
//code to do something on new window | |
driver.close(); // close newly opened window when done with it | |
driver.switchTo().window(parentHandle); // switch back to the original window |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment