Monday, 24 February 2014

How To Close Popup Window in Selenium Webdriver


This Method will Solve Your Problem:


private void  handleWindow() {
 try {
      String parent = driver.getWindowHandle();

      Set<String> pops=driver.getWindowHandles();
       {
 Iterator<String> it =pops.iterator();
while (it.hasNext()) {

 String popupHandle=it.next().toString();
 if(!popupHandle.contains(parent))
{
                   driver.switchTo().window(popupHandle);
 System.out.println("Popu Up Title: "+ driver.switchTo().window(popupHandle).getTitle());
 driver.close();
  driver.switchTo().window(parent);  // control is moving to parent window
        }
       }
}
} catch (NoAlertPresentException e) {
         e.printStackTrace();
 }

}

No comments:

Post a Comment

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...