October 2018
Intermediate to advanced
192 pages
5h 12m
English
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()); }}
Read now
Unlock full access