Waiting for Elements in an IFrame on a WebPage to Load

>Waiting for a page to load while writing selenium scripts is pretty straightforward using the
selenium.WaitForPageToLoad(“timeout”) timeout is time in millisecond.

Sometimes using this command doesn’t work, especially when you the whole page is not loaded or reloaded but a popup is loaded in a div on the page. In situation like this i would used the
selenium.WaitForCondition(“ScriptToReturnwhich ReturnTrue OrFalse“, “timeout”);
e.g. of scripts would be

selenium.WaitForCondition(selenium.browserbot.get CurrentWindow().document
.getElement ById(‘idOfElement ToBelocated’)!=null”, “60000”);

This has always worked well for well until today, i had a special case where the element that i needed to wait for it to load was inside an IFrame, which is loaded within a parent page. Using the Wait for condition as above kept timing out as the Javascript could not access the IFrame.

what worked for me after several hours of trying is:

selenium.WaitForCondition(“selenium.browserbot.getCurrent Window()
.frames[‘Name Of IFrame’].document.get Element ById
‘idOfElement ToBelocated’)!= null”, “60000”);

This brilliantly eliminated my nightmare …….

Comments are welcome

Advertisements
This entry was posted in Software Testing and tagged , , , , . Bookmark the permalink.

One Response to Waiting for Elements in an IFrame on a WebPage to Load

  1. Jatin says:

    >This just might help solve a similar problem I have, thanks a lot!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s