问题
I am experimenting with CodedUI using C# and am having some trouble. I have got a <div>
containing an ID, and then a non-uniquely identified <ul>
with several <li>
tags like the below:
<div id="uniqueIdValue" class"long_class" activetabindex="0" sfwtabcontainer="true">
<ul class="long_class2">::before
<li class="sharedListItemClass" sfwtabheader="true">...</li>
<li class="sharedListItemClass" sfwtabheader="true">
<a href="#someValue">History</a>
</li>
<li class="sharedListItemClass" sfwtabheader="true">...</li>
::after
</ul>
How can I setup a Mouse.Click(...)
on the the second list item (or the <a>
within) containing my <a>
tag with test of "History"?
I have tried every combination I can think of to specify this tag by itself, all the way up to specifying the parent and trying to get the "TagInstance":
var container = new HtmlControl(_bw);
HtmlDiv nameForDiv = new HtmlDiv(container);
nameForDiv.SearchProperties[HtmlDiv.PropertyNames.Id] = "uniqueDivIdentifier";
nameForDiv.SearchProperties[HtmlDiv.PropertyNames.Class] = "long Multiple_Classes";
var historyTab = new HtmlHyperlink(nameForDiv);
historyTab.SearchProperties[HtmlHyperlink.PropertyNames.Href] = "#someValue";
historyTab.SearchProperties[HtmlHyperlink.PropertyNames.TagInstance] = "2";
Mouse.Click(historyTab)
Resulting in the control cannot be found. Can anyone help me with this?
回答1:
Something like this:
var browser = BrowserWindow.Launch("url");
private void ClickLink()
{
var parent = GetPaneID(browser, "uniqueIdValue");
var child = parent.GetChildren()[0];
var child2 = child.GetChildren()[1];
var child3 = child2.GetChildren()[0];
Mouse.Click(child3);
}
where method GetPaneId() looks like this:
public HtmlDiv GetPaneID(UITestControl parent, string id)
{
var gpane = new HtmlDiv(parent);
gpane.SearchProperties.Add(HtmlDiv.PropertyNames.Id, id);
return gpane;
}
来源:https://stackoverflow.com/questions/40158387/codedui-find-lower-level-list-item-without-an-id