Saturday, July 22, 2017

Switch between Windows using switch to in Selenium


String MainWinHandle = driver.getWindowHandle();
for(String NewWinHandle : driver.getWindowHandles()){
// Ignore the parent window open and work with the new window frame
 if(!NewWinHandle.equals(MainWindowHandle))
  {
    driver.switchTo().window(NewWinHandle);
 //Perform the required tasks to be performed in the new window opened
 driver.close();
 }
}
//Perform action on the main window once the task is completed with the old window.
driver.switchTo().window(MainWinHandle);

No comments:

Post a Comment