Cannot see objects/Elements within an iFrame

5 posts, 0 answers
  1. David
    David avatar
    45 posts
    Member since:
    Aug 2010

    Posted 16 Nov 2010 Link to this post

    I am having trouble getting to elements within an iFrame. I believe I have the iFrame identified but getting in to the iFrame seems to be escaping me. I have looked through the forums and documentation for the past couple days but cannot seem to get it.

    When the desired iFrame is identified, there are no children to the iframe tag. Does this need to be cast to a new browser? Do I take the src attribute and use that within a new Browser element?

    Any help would be appreciated.
  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 22 Nov 2010 Link to this post

    Hello David,

    Getting to the contents of an IFrame is pretty easy once you know the secret. Just use code like this:

    // Get at the frame by name
    Browser myFrame = ActiveBrowser.Frames["myFrameName"];
     
    // Get at the frame by index number
    Browser myFrame = ActiveBrowser.Frames[0];
     
    HtmlButton myButton = myFrame.Find.ById<HtmlButton>("myButtonID");
    myButton.Click();

    Does that answer your question?

    Regards,
    Cody
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. wilfredo
    wilfredo avatar
    13 posts
    Member since:
    Jun 2011

    Posted 13 Jun 2011 Link to this post

    Mine wasn't working. Can' find or return any elements under my frame.

    It's already fix.. thx.. frame.RefreshDOmtree(); is used. thank you!!!
  4. chandra
    chandra avatar
    1 posts
    Member since:
    Dec 2014

    Posted 18 Dec 2014 Link to this post

    Hi Cody,

    I am able to access the elements in IFrame but after that I am
    unable to access the elements in the active browser:

    I am posting the code I have written.

    Element newElement = Manager.ActiveBrowser.Find.ByContent("New");
    Manager.ActiveBrowser.Actions.Click(newElement);

    Browser myFrame = Manager.ActiveBrowser.Frames["rbe_popupFrame"];
    Element ele = myFrame.Find.ByContent("A new Object (with Tab)");
    myFrame.Actions.Click(ele);
    Element create = myFrame.Find.ByAttributes("value=~Create");
    myFrame.Actions.Click(create);

    Manager.ActiveBrowser.RefreshDomTree();
    Element singularName = Manager.ActiveBrowser.Find.ByName("singularName");
    Manager.ActiveBrowser.Actions.SetText(singularName, "Object1");

    Here after clicking on New the IFrame will be open. And able to access the elements in the IFrame. The IFrame will be closed when we click on create. Then after that I want to enter the value in the textbox which is there in the browser.  But after closing the IFrame I am getting time out exception.

    InnerException:System.TimeoutException: Wait for condition has timed out
     at ArtOfTest.Common.WaitSync.CheckResult(WaitSync wait, String extraExceptionInfo, Object target)
     at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout, WaitResultType errorResultType)
     at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout)
     at ArtOfTest.WebAii.Core.Browser.WaitUntilReady()
     at ArtOfTest.WebAii.Core.Browser.ExecuteCommand(BrowserCommand request, Boolean performDomRefresh, Boolean waitUntilReady)
     at ArtOfTest.WebAii.Core.Browser.ExecuteCommand(BrowserCommand request)
     at ArtOfTest.WebAii.Core.Actions.Click(Element targetElement)
     at new_test_project.WebTest_1_.WebTest1_CodedStep() in c:\Program Files(x86)\Telerik\Test Studio\Samples\Test Studio\DemoTests\WebTest(1).tstest.cs:line 384
  5. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 22 Dec 2014 Link to this post

    Hi David,

    Yes sometimes you do need to call RefreshDomTree();. We cache the browsers DOM in memory for performance reasons. There are instances in which the cached copy will get stale and RefreshDomTree updates it for you.

    Notice this line from the stack trace:
    at ArtOfTest.WebAii.Core.Browser.WaitUntilReady()

    What's actually happening is that Test Studio is timing out waiting for the browser to return to the "Ready" state after performing the click. There are a couple of ways to handle this:

    1) Increase the ClientReadyTImeout property. This will fix it if the current timeout is simply not long enough. I believe the default value is 30 seconds. Sometimes a click that causes an action on the backend to happen can take longer.

    2) If the browser actually never returns to the "Ready" state, use a mouse click instead of the .Click like this:

    Manager.Desktop.Mouse.Click(MouseClickType.LeftClick, create.GetRectangle());

    I hope this helps.

    Regards,
    Cody
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top