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

You Might Also Like
Comments
comments powered by Disqus