CodedUI查找没有ID的较低级列表项? [英] CodedUI Find lower level List Item without an ID?
问题描述
我正在使用C#对CodedUI进行试验,遇到了一些麻烦.我有一个包含ID的<div>
,然后是带有几个<li>
标记的非唯一标识的<ul>
,如下所示:
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>
我如何在包含我的<a>
标记的第二个列表项(或其中的<a>
)上设置Mouse.Click(...)
并进行历史记录"测试?
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"?
我尝试过可以想到的每种组合,以自行指定该标签,一直到指定父级并尝试获取"TagInstance":
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?
推荐答案
类似以下内容:
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);
}
其中GetPaneId()方法如下:
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;
}
这篇关于CodedUI查找没有ID的较低级列表项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!