How can I switch tabs in a test with Java-Selenide?
Hello Charity,
You can refer to the sample code snippet below to switch tabs in a test with Java-Selenide:
//Store the ID of the original window
String originalWindow = driver.getWindowHandle();
//Check we don't have other windows open already
assert driver.getWindowHandles().size() == 1;
//Click the link which opens in a new window
driver.findElement(By.linkText("new window")).click();
//Wait for the new window or tab
wait.until(numberOfWindowsToBe(2));
//Loop through until we find a new window handle
for (String windowHandle : driver.getWindowHandles()) {
if(!originalWindow.contentEquals(windowHandle)) {
driver.switchTo().window(windowHandle);
break;
}
}