Selenium and Java

Tuesday, 14 April 2015

Selenium - Multiple windows in Selenium Webdriver

Selenium can handle multiple windows using inbuilt method getWindowHandles().
Code for the same as below.

WebDriver driver =  new InternetExplorerDriver();
Set<String> allWindows =  driver,getWindowHandles();

for (String allWindow : allWindows ) {
driver.switchTo().window(allWindow);

if (driver.getTitle().equalsIgnoreCase("VIP Database")){
              driver.manage().window().maximize(); 
              driver.findElement(By.cssSelector("button")).click();
          }
}

No comments:

Post a Comment