When and how to use switchTo() method in webDriver (Selenium 2) to handle window/pop up

You may try to switch to the window again after the redirect.

Save you window handle:

String myWindowHandle = driver.getWindowHandle();

redirect to the page you want and then call switchTo using the window handle:

driver.switchTo().window(myWindowHandle );

Does your page contain any frames? It may also be possible that you are not in the correct frame after the redirect.

Leave a Comment