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 30, 2018 in Selenium by Shubham
• 13,490 points
2,221 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 30, 2018 by nsv999
• 5,500 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, 2019 by Abha
• 28,140 points

Related Questions In Selenium

0 votes
1 answer

How to switch back from a frame to default in Selenium Webdriver?

Hey Rupesh, to switch back from a ...READ MORE

answered Jun 25, 2019 in Selenium by Anvi
• 14,150 points
12,077 views
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 27, 2019 in Selenium by Abha
• 28,140 points
1,532 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,500 points
2,854 views
0 votes
2 answers

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,500 points
12,620 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,572 views
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,910 points
6,629 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,519 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,500 points
2,124 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
• 58,090 points
23,397 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP