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,300 points
159 views

2 answers 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,090 points
0 votes

Hi Shubham, you can switch to a frame using this:

driver.switchTo.frame("Frame_ID");

And to switch back to the default frame, you can use this:

driver.switchTo().defaultContent();
answered Aug 26 by Abha
• 25,240 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

Which method is used to switch to a frame on a webpage using Ruby Selenium Webdriver?

Hi Hemant, you can use driver.switch_to.frame method to switch ...READ MORE

answered Aug 26 in Selenium by Abha
• 25,240 points
29 views
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,090 points
869 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,090 points
780 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
1,025 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
726 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,090 points
564 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,900 points
8,171 views