-
-
Save angiejones/0069465a3bfc8b0999f5f7d4412b8a5a to your computer and use it in GitHub Desktop.
Window management in Selenium 4
This file contains 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
public void windowsAndTabs() { | |
//Open initial window | |
driver.get("https://applitools.com/"); | |
//Open new tab. If you want a new browser window, use WindowType.WINDOW | |
driver.switchTo().newWindow(WindowType.TAB); | |
driver.get("https://testautomationu.com"); | |
//Switch between windows/tabs by using window handles | |
var windows = driver.getWindowHandles(); | |
for(var window : windows){ | |
driver.switchTo().window(window); | |
if("Automated Visual Testing with Visual AI".equals(driver.getTitle())){ | |
//This is the tab I want in focus, so stop looping. | |
break; | |
} | |
} | |
System.out.println(driver.getTitle()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment