Reputation: 1
I am working on the following scenario.
I click on an element in the main web page and it opens a dialog box. It is an iframe and i use diver.switchTo().frame(1);
to access that frame. I am able to perform the required activites in that frame. Clicking on OK button in that frame will close it. Once the frame is closed i am not able to access any of the elements in the main page. I used the following to switch back to main page
driver.switchTo().defaultContent()
and driver.switchTo().frame(0)
. But none of them let me get back to the main page.
Since the frame gets closed i also tried without any switchTo() statements. But it didnt work either.
Please help me with other possible solutions for it. Thanks in advance!
Upvotes: 0
Views: 1493
Reputation: 193068
As you are trying to switch back to the Top-Level Browsing Context your following code trial should have worked :
driver.switchTo().defaultContent();
As an alternative you can also try :
driver.switchTo().parentFrame();
Sometimes it may happen that the driver looses the window focus and in that case you have to regain the focus on the browser by :
((JavascriptExecutor) driver).executeScript("window.focus();");
Upvotes: 0
Reputation: 50809
You need to switch back to the original window (Java code)
String windowHandle = driver.getWindowHandle(); // save the original window handle
// handle the pop up
driver.switchTo().window(windowHandle);
Upvotes: 2