How to change browser instance in Selenium- Java? WebDriver could not locate the elements on the screen after clicking on second webpage
1 Answer
// 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);