Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Test
public void windowFrames() {
driver.navigate().to("https://the-internet.herokuapp.com/windows");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(("window.open('https://the-internet.herokuapp.com/windows/new')"));
String originalWindow = driver.getWindowHandle();
Set handles = driver.getWindowHandles();
handles.remove(originalWindow);
String nextWindow = String.valueOf(handles.iterator().next());
driver.switchTo().window(nextWindow);
Assert.assertEquals("New Window", driver.getTitle());
driver.close();
driver.switchTo().window(originalWindow);
Assert.assertEquals("The Internet", driver.getTitle());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment