0

How to change browser instance in Selenium- Java? WebDriver could not locate the elements on the screen after clicking on second webpage

Chandra Shekhar
  • 664
  • 2
  • 9
  • 24
  • [**This**](http://stackoverflow.com/questions/19117747/how-to-switch-between-two-windows-in-browser-using-selenium-java) or [**this**](http://stackoverflow.com/questions/9588827/how-to-switch-to-the-new-browser-window-which-opens-after-click-on-the-button) answers might be useful. – ManishChristian Jun 07 '16 at 14:54

1 Answers1

0

// First store the current window instance

String winHandleBefore = driver.getWindowHandle();

// After your click operation which opens the new window

// Below code Switches instance to the new window

for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);

}

// If you want to switch back to the original window

driver.switchTo().window(winHandleBefore);
Mahesh
  • 129
  • 1
  • 2
  • 19