Cannot see objects/Elements within an iFrame

16 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
    3354 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
    3354 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
     
  6. Sakthi
    Sakthi avatar
    8 posts
    Member since:
    Jan 2018

    Posted 11 Jun 2018 in reply to Cody Link to this post

    Hello David.

    Thanks for handling IFrame. But I have a scenario, that is there is a PDF present in inside the IFrame. I have to verify the PDF content dynamically. There is no option available for to read the LIVE PDF content and also, the PDF content changes dynamically.

    Any help would be appreciated.

  7. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    1049 posts

    Posted 14 Jun 2018 Link to this post

    Hi Sakthivel,

    Thank you for reaching us out. 

    Test Studio interacts with the html structure and html elements in it. The pdf content is not part of the html of the page and therefore Test Studio will not be able to read that content. 

    If you download the pdf file you could implement coded solution to read that file and perform verifications against it. 

    Please let me know if you need further assistance!

    Regards,
    Elena Tsvetkova
    Progress Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  8. Renjila
    Renjila avatar
    10 posts
    Member since:
    Jul 2018

    Posted 01 Aug 2018 Link to this post

    Hello,

    I am facing issue in capturing the step to enter value in the html body with in a iframe.

    here is my iframe.

    <iframe id="description-2215-inputCmp-iframeEl" data-ref="iframeEl" name="ext-2104" frameborder="0" src="about:blank" class="x-htmleditor-iframe" data-componentid="description-2215">
       <html>
          <head>
             <style type="text/css">body{border:0;margin:0;padding:3px;direction:ltr;min-height:192px;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;cursor:text;background-color:white;font-size:12px;font-family:"Segoe UI"}</style>
          </head>
          <body style="font-size: 16px; font-family: &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif; background-image: none; background-repeat: repeat; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); background-attachment: fixed; cursor: text;">TestHello</body>
       </html>
    </iframe>

    On recording, it is is capturing the iframe click step.

    How to add the step of entering the test in the html body, here its "TestHello"

    Any help would be appreciated.

    Thanks and Regards,

    Renjila

     

     


  9. Sakthi
    Sakthi avatar
    8 posts
    Member since:
    Jan 2018

    Posted 01 Aug 2018 in reply to Renjila Link to this post

    Hi Renjila,

    If you want to handle elements within IFrame, first you have to handle IFrame, then only we can handle elements within the IFrame.

    Below mentioned the code.

    Browser IFrame=_manager.ActiveBrowser.Frames.ById("description-2215-inputCmp-iframeEl"); /* To capture the IFrame using IFrame ID.*/

    Element recObj = IFrame.Find.ById(locatorValue); /*With the help of IFramewe can handle the elements*/
    recObj.Focus();
    _manager.ActiveBrowser.Actions.SetText(recObj, "");
    _manager.Desktop.KeyBoard.TypeText(value);

    It will help you lot.

    Regards,

    Sakthi.

     

     

  10. Renjila
    Renjila avatar
    10 posts
    Member since:
    Jul 2018

    Posted 02 Aug 2018 in reply to Sakthi Link to this post

    Hello Sakthi,

    Thank you for the quick response.

     In my scenario ,how to locate the body tag, as it does not have the id.

    Element recObj = IFrame.Find.ById(locatorValue);

    Regards,

    Renjila Rajan

  11. Sakthi
    Sakthi avatar
    8 posts
    Member since:
    Jan 2018

    Posted 02 Aug 2018 in reply to Renjila Link to this post

    Hi Renjila,

    You can use XPath to capture the body tag.

    Eg:

    Element recObj = IFrame.Find.ByXPath("/html/body");

     

    Regards,

    Sakthi.

  12. Renjila
    Renjila avatar
    10 posts
    Member since:
    Jul 2018

    Posted 02 Aug 2018 Link to this post

    Hello Sakhti,

     Thank you for your input.

     Now the problem here is its throwing error in SetText method saying the element passed is null.

    Pages.Https1013129.Description2217InputCmpIframeElIFrame.Click(false);
    Pages.Https1013129.Description2217InputCmpIframeElIFrame.Refresh();
    Browser IFrame=Manager.ActiveBrowser.Frames.ById("description-2217-inputCmp-iframeEl");
    if(IFrame==null)
    {
    Log.WriteLine("frame is null");
    }

    Element recObj = IFrame.Find.ByExpression("TagIndex=html:0");
    Element recObj2 = IFrame.Find.ByXPath("/html/body");
    logValue(recObj);
    logValue(recObj2);
    if(recObj2!= null)
    {
    Manager.ActiveBrowser.Actions.SetText(recObj, "Hello");
    }

     

    When I checked in the DOM during runtime, I could see the html and body tag . Please let me know , what could be the issue for this null object then.

    Thanks in advance

    Renjila

     

  13. Renjila
    Renjila avatar
    10 posts
    Member since:
    Jul 2018

    Posted 02 Aug 2018 in reply to Renjila Link to this post

    oops! sorry! that was a minor mistake of variable. Its not that error. The issue here :

    Target '[Element: 'body:0']' is not a supported element to set text to.

  14. Renjila
    Renjila avatar
    10 posts
    Member since:
    Jul 2018

    Posted 02 Aug 2018 in reply to Renjila Link to this post

    oops sorry! that was not the issue. that was because a typo.

    The issue is Target '[Element: 'body:0']' is not a supported element to set text to.

  15. Renjila
    Renjila avatar
    10 posts
    Member since:
    Jul 2018

    Posted 03 Aug 2018 Link to this post

    Hello,

    I couldn't get how to assign value to body tag ; however I used a workaround by focusing the IFrame and using TypeTest, which resolved my issue.

    Thanks !

  16. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    1049 posts

    Posted 06 Aug 2018 Link to this post

    Hi guys,

    I am glad to see you collaborated on this issue. I hope it is all fine now. Though in case of further assistance required please do not hesitate to contact us again! 

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