Wednesday 2 September 2015

Handling multiple windows with Selenium WebDriver



With the help of below code you can easily handle different windows and can perform different operations

 

 
       // Store current window handle  
      String winHandleBefore = driver.getWindowHandle();  
   
      //Click on element which opens new window  
   
      // Switch to new window opened  
      for (String winHandle : driver.getWindowHandles())  
      {  
        driver.switchTo().window(winHandle);  
      }    
   
     // perform operation that opens new window  
           
     // Close the new window  
      driver.close();  
   
    // Switch back to original window  
    driver.switchTo().window(winHandleBefore);  
   

 

No comments:

Post a Comment