Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Created August 20, 2020 10:22
Show Gist options
  • Save angelovstanton/5db5f255eb15aa8fa480de530de0c114 to your computer and use it in GitHub Desktop.
Save angelovstanton/5db5f255eb15aa8fa480de530de0c114 to your computer and use it in GitHub Desktop.
@Test
public void movingBetweenTabs() {
driver.navigate().to("https://www.automatetheplanet.com/");
var firstLink = driver.findElement(By.xpath("//*[@id='menu-item-11362']/a"));
var secondLink = driver.findElement(By.xpath("//*[@id='menu-item-6']/a"));
String selectLinkOpenninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
firstLink.sendKeys(selectLinkOpenninNewTab);
secondLink.sendKeys(selectLinkOpenninNewTab);
Set<String> windows = driver.getWindowHandles();
String firstTab = (String)windows.toArray()[1];
String lastTab = (String)windows.toArray()[2];
driver.switchTo().window(lastTab);
Assert.assertEquals("Resources - Automate The Planet", driver.getTitle());
driver.switchTo().window(firstTab);
Assert.assertEquals("Blog - Automate The Planet", driver.getTitle());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment