Unable to switch back to default frame

0 votes
I am working on the following scenario.

I have a main web page in which there is an element which opens a dialog box. It is an IFrame and when i use diver.switchTo().frame(1); to access the new popup, i can access that frame. And I'm also able to perform the required activites in that same frame. And when I click on the "OK" button in that frame, the frame gets closed. Once this frame is closed, i'm not able to access any of the elements in my main page. I used the these switch back function calls to go back to the main page:
driver.switchTo().defaultContent() and driver.switchTo().frame(0). Since the frame gets closed i also tried without any switchTo() statements. But none of them gives me control of the main page.

Can somebody suggest solutions for it? Thanks in advance!
Mar 29, 2018 in Selenium by Shubham
• 13,190 points
84 views

1 answer to this question.

0 votes

That's because you should switch back to the original window by saving the window handle in an object. Check the below code:

String windowHandle = driver.getWindowHandle(); // save the original window handle

driver.switchTo().window(windowHandle); // handle the pop up
answered Mar 29, 2018 by nsv999
• 5,050 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Need to switch between frames in Selenium

For switching between frames, use driver.switchTo().frame(). First ...READ MORE

answered Apr 6, 2018 in Selenium by nsv999
• 5,050 points
583 views
0 votes
1 answer

Unable to use Selenium IDE & Firebug on Firefox

Unfortunately, Selenium IDE will not work anymore ...READ MORE

answered Apr 9, 2018 in Selenium by nsv999
• 5,050 points
71 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
259 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
628 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
256 views
0 votes
1 answer

Unable to connect to chromedriver 127.0.0.1:9515 on Amazon Linux AMI server

The issue seems to be only with ...READ MORE

answered Mar 26, 2018 in Selenium by nsv999
• 5,050 points
476 views
0 votes
2 answers

Unable to Click on an Element in Selenium (Python) even after finding it.

Here, I give you working script which ...READ MORE

answered Sep 19, 2018 in Selenium by Priyaj
• 56,160 points
5,959 views