Skip to content

Instantly share code, notes, and snippets.

@ultimate-qa2
Created February 28, 2021 18:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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