Looping through all open windows using the simple for loop

Sometimes, using a simple for loop instead of a set can prove easy to comprehend. Let's look at the ArrayList method with the same link http://popuptest.com/goodpopups.html.

The following code, when run from a main method, prints the titles of each popup:

 WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("http://popuptest.com/goodpopups.html");
try {
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.findElement(By.xpath("//*[text()='Good PopUp #1']")).click();
for (String i : driver.getWindowHandles()) {
driver.switchTo().window(i);
System.out.println(driver.getTitle());
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.174.95