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

Issue finding iFrame and its children

4 Answers 518 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tomina
Top achievements
Rank 1
Tomina asked on 21 Jul 2016, 05:04 PM
I've been automating tests for a specific website for some time now. I am using Testing Framework Version 2014.2.618.0 Free Edition with c# for chrome browser.
I am having trouble getting an iFrame element and elements within it from one of the pages.
Html structure is the following:
<div id="rightContainer" role="main">
<section class="application-plugin using-bootstrap"></section>
<iframe scrolling="no" allowtransparency="true" class="application-plugin-iframe" allowfullscreen="true" style="width: 100%; overflow: hidden; height: 928px;" src="http://plugins/application...">
#document
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<div id="PluginTarget" "></div>
<div class="plugin-landing-page ">
<div class="plugin-landing-page-tiles clearfix ">
::before
<div class="col-md-4 col-sm-4 plugin-program-container ">
<div class="plugin-program "></div>//I want to click at this element
</div>
<div class="col-md-4 col-sm-4 plugin-program-container ">...</div>
</div>  
</body>
</html>
</iframe>                                 
</section>
<div style="display:none; "></div>
</div>


Note that ‘#document’ is a shadow DOM element.
What I tried so far to access the iFrame:
1)
Manager.ActiveBrowser.Frames.RefreshAllDomTrees();
Manager.ActiveBrowser.RefreshDomTree();
Manager.ActiveBrowser.Frames.WaitAllUntilReady();
int framesNumber = Manager.ActiveBrowser.Frames.Count;
Browser topFrame = Browser.Manager.ActiveBrowser.Frames["application-plugin-iframe"];
topFrame.RefreshDomTree();

topFrame is always null no matter how many times and in what sequence I’ve refreshed.
framesNumber is always null too.

2)

var topFrame = Manager.ActiveBrowser.Find.ByAttributes<HtmlControl>(string.Format("{0}={1}", "class", "application-plugin-iframe"));
Predicate<HtmlControl> filter = new Predicate<HtmlControl>((control) => control.Attributes.Any(a => a.Name == "class=" && a.Value=="plugin-program"));
var myBox =topFrame.Find.ByCustom<HtmlControl>(filter);

Using this approach I’m able to get the iFrame as HtmlControl or HtmlContainerControl element but myBox element is always null.

3)

var iFrame1 = Browser.Find.ByExpression("tagname=iframe");
var iFrameHtmlControl = new HtmlControl (iFrame1);
IUiSearchable searchable = new SearchableUiContext<HtmlControl>(iFrameHtmlControl);
searchable.Refresh();
HtmlControl result = searchable.Find.ByAttributes<HtmlControl>(string.Format("{0}={1}", "class", "plugin-program"));

Here again I’m able to get iFrame1 and iFrameHtmlControl elements and to Refresh but result is again null
4)
I tried getting the iframe
var topFrame = Manager.ActiveBrowser.Find.ByAttributes<HtmlControl>(string.Format("{0}={1}", "class", "application-plugin-iframe"));

And then getting all its child elements with a recursive method which is basically doing
allSubElements.AddRange(start.ChildNodes);
 for each child
I always get just one child element for topFrame - the Shadow DOM which doesn’t have children so here I figured out that the Shadow DOM element could be the cause of my problems but I’m not sure.

5)

Manager.ActiveBrowser.Actions.InvokeScript("$('body /deep/ #PluginTarget .plugin-program.click();");

This script worked when executed in Chrome Browser console but I need to click inside the Shadow DOM before. I still can’t do that from the test so executing JavaScript to click the desired element also failed.

As you can see I'm running out of ideas for this issue which is quite frustrating. Since the main logic of my app reside in that iFrame not being able to operate with it is a true deal breaker for me. 

Thank you in advance for any help.

Kind regards,

4 Answers, 1 is accepted

Sort by
0
Elena
Telerik team
answered on 26 Jul 2016, 03:41 PM
Hi Tomina,

Thank you for choosing Telerik Testing Framework. 

I appreciate your cooperativeness and willing to share so many details. They will certainly be of great help for us to test this on our side. Probably the issue is that the frame is not correctly located but I will need some time to review it. Please allow me few more days and I will get back to you once I have actual results. Thank you in advance for your understanding! 

Regards,
Elena Tsvetkova
Telerik by Progress
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Elena
Telerik team
answered on 04 Aug 2016, 11:53 AM
Hi Tomina,

Thank you for your patience. I now reviewed the provided html code and your scenario. First of all I would like to ask you to upgrade your framework to the latest available internal build version. For almost two years there are a lot of things that were fixed. 

Then you could use the following class to locate the particular frame: 

FrameInfo frameInfo = new FrameInfo("ID", "NAME", "SRC", 1);

where you could use at least one parameter and leave the rest unknown empty. I guess it will work if you set "application-plugin-iframe" as and ID or Name depending on its exact role. Then set the frame as an active browser: 

Regards,Manager.Browser frame = Manager.ActiveBrowser.Frames[frameInfo];

After that you could search for the elements in the frame as you have already done. However one of the most important things to do is to update your Test Studio Framework. Please let me know if you would require further assistance. Thank you! 

Elena Tsvetkova
Telerik by Progress
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Tomina
Top achievements
Rank 1
answered on 08 Aug 2016, 09:18 AM

Hi Elena, 

Thank you for the assistance with that matter.

I followed your suggestion and updated Telerik Framework to the latest version I could find - 2016.2.630.0 and the issue was resolved there. The iFrame is found with no problem By 'name'. 

Afterwards I found that Testing Framework - 2014.2.618.0 also finds the iFrame with no problem however as far as I tried only for Chrome versions 52.0.2704.* and not when using the latest one.

Thank you for the help.

Regards,

Tomina Petrova

0
Elena
Telerik team
answered on 10 Aug 2016, 11:47 AM
Hello Tomina,

I am glad to hear you have figured that out. Do not hesitate to contact Test Studio Support Team in case of any future questions. Wish you great day ahead! 

Regards,
Elena Tsvetkova
Telerik by Progress
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Tomina
Top achievements
Rank 1
Answers by
Elena
Telerik team
Tomina
Top achievements
Rank 1
Share this question
or