I am writing tests on a third party system, that utilizes iframes. I have been going through my code and eliminating places where I have been using waits/sleep for 2-5 seconds, and looking more for elements to show.

But, there is one frame, where I have a wait for 90 seconds, because it can take a long time to process, and can take 2 seconds to process in our test system. So, the only way I would know is that the frame is closed and returned back to the main window. I looked to see if I can find out if I am on a frame or a page from the Driver.Instance.... but I can't see anything in particular that could help. What should I look for to see if I am still on a frame, or control has returned to the calling web page?


I answered my own question, and went through the wait helper, one by one, and found this one... that I didn't think about.


Waited for the button to be clickable before clicking on it.

| improve this answer | |

Although, your haven't mentioned the language. Refer below code (Java) to dynamically wait for the iFrame and switch into it

WebDriverWait wait = new WebDriverWait(driver, 60);

It will wait until your frame gets in into web page and then switch in.

There you can write the code to perform the action on iframe element and then switch back to default window

| improve this answer | |
  • I understand how to close a frame...I am looking on what to look for to know when it closes...if I just close this, and return back to the defaultContent, and it takes more than a second to process, I get this. Element <i class="collapse-icon fa fa-fw fa-refresh"></i> is not clickable at point (1766, 542). Other element would receive the click: <div class="ui-widget-overlay ui-front" style="z-index: 100;"></div>, because the frame is still open, processing. I was hoping for some wait helper for this. – Greg P Feb 5 '19 at 12:48

In Webdriver, you should use driver.switchTo().defaultContent(); to get out of a frame. You need to get out of all the frames first, then switch into the outer frame again.

// between step 4 and step 5
// remove selenium.selectFrame("relative=up");
driver.switchTo().defaultContent(); // you are now outside both frames
// now continue step 6
| improve this answer | |
  • Let me know it helps or not. – Meet Feb 12 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.