【发布时间】:2014-09-09 17:17:34
【问题描述】:
我在选择 Microsoft 的 CodedUI 框架中的项目时遇到了问题。我有一页充满了可以通过选择复选框来添加/删除的项目。复选框上没有唯一的 id,在查找特定标签/类组合时,我无法选择第一个项目以外的项目。是否有一些不是很明显的技巧来做到这一点。
【问题讨论】:
标签: coded-ui-tests
我在选择 Microsoft 的 CodedUI 框架中的项目时遇到了问题。我有一页充满了可以通过选择复选框来添加/删除的项目。复选框上没有唯一的 id,在查找特定标签/类组合时,我无法选择第一个项目以外的项目。是否有一些不是很明显的技巧来做到这一点。
【问题讨论】:
标签: coded-ui-tests
这里有几个不同的选项:
1.您可以通过选择与之相关的项目来选择对象
<div id="parent">
<label id="checkbox1234">MyCheckBox</label>
<input checked="false"></input>
</div>
...可以选择为:
HtmlDiv parent = new HtmlDiv(browserWindow);
parent.SearchProperties["innerText"] = "MyCheckBox";
HtmlCheckBox target = new HtmlCheckbox(parent);
target.SearchProperties["TagName"] = "INPUT";
return target;
或
HtmlLabel sibling = new HtmlLabel(browserWindow);
sibling.SearchProperties["id"] = "checkbox1234";
UITestControlCollection col = sibling.GetParent().GetChildren();
foreach (UITestControl control in col)
{
if (control.ControlType.ToString().Equals("HtmlCheckBox"))
{
return (HtmlCheckBox)control;
}
}
【讨论】: