19 November, 2014

How to switch to different browser window from current window in Selenium webdriver?

Step1: Store the Main window handle
          
 String Parentwindow = driver.getWindowHandle( );  


Step2: Click on the Link which will open the new Browser window

Step3: Switch to the new open browser window.
          
  for ( String currentwindow : driver.getWindowHandles())  
  driver.switchTo( ).window(currentwindow);  
       {  
       // Perform your operations on the current window    
         driver.close( )  
       }  


Step4: Return to the Main window
          
  driver.switchTo().window(Parentwindow);  


1 comment: