Wednesday, 29 October 2014

How to switch from one window to other using selenium webdriver?








//Returns all the available window id’s
Set<String> WINDOWIDS= driver.getWindowHandles();
Iterator<String> iter=WINDOWIDS.iterator();    
String Window1=iter.next();//Returns first window id
String Window2=iter.next();//Returns second window id
driver.switchTo().window(Window2);//Focus will be switched to second window

//Perform actions on Window2

driver.close();//It will close the second window
driver.switchTo().window(Window1);//Focus will be switched to first window

//Perform actions on Window1

driver.close();//It will close the first window