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:
Note that ‘#document’ is a shadow DOM element.
What I tried so far to access the iFrame:
1)
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
And then getting all its child elements with a recursive method which is basically doing
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.
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);
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,