This is a migrated thread and some comments may be shown as answers.

Cannot see objects/Elements within an iFrame

15 Answers 536 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 17 Nov 2010, 12:11 AM
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.

15 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 22 Nov 2010, 11:23 PM
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
0
wilfredo
Top achievements
Rank 1
answered on 14 Jun 2011, 03:59 AM
Mine wasn't working. Can' find or return any elements under my frame.

It's already fix.. thx.. frame.RefreshDOmtree(); is used. thank you!!!
0
chandra
Top achievements
Rank 1
answered on 18 Dec 2014, 03:26 PM
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
0
Cody
Telerik team
answered on 23 Dec 2014, 01:35 AM
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
 
0
Sakthi
Top achievements
Rank 1
answered on 11 Jun 2018, 09:10 AM

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.

0
Elena
Telerik team
answered on 14 Jun 2018, 08:39 AM
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
 
0
Renjila
Top achievements
Rank 1
answered on 02 Aug 2018, 03:23 AM

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

 

 


0
Sakthi
Top achievements
Rank 1
answered on 02 Aug 2018, 03:55 AM

Hi ,

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.

 

 

0
Renjila
Top achievements
Rank 1
answered on 02 Aug 2018, 05:45 AM

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

0
Sakthi
Top achievements
Rank 1
answered on 02 Aug 2018, 06:00 AM

Hi ,

You can use XPath to capture the body tag.

Eg:

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

 

Regards,

Sakthi.

0
Renjila
Top achievements
Rank 1
answered on 03 Aug 2018, 03:21 AM

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

 

0
Renjila
Top achievements
Rank 1
answered on 03 Aug 2018, 03:38 AM

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.

0
Renjila
Top achievements
Rank 1
answered on 03 Aug 2018, 03:39 AM

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.

0
Renjila
Top achievements
Rank 1
answered on 03 Aug 2018, 07:53 AM

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 !

0
Elena
Telerik team
answered on 06 Aug 2018, 11:49 AM
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
 
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Cody
Telerik team
wilfredo
Top achievements
Rank 1
chandra
Top achievements
Rank 1
Sakthi
Top achievements
Rank 1
Elena
Telerik team
Renjila
Top achievements
Rank 1
Share this question
or