【问题标题】:Visual Studio Coded UI: Select HTML Element by CSS SelectorVisual Studio Coded UI:通过 CSS 选择器选择 HTML 元素
【发布时间】:2014-09-09 17:17:34
【问题描述】:

我在选择 Microsoft 的 CodedUI 框架中的项目时遇到了问题。我有一页充满了可以通过选择复选框来添加/删除的项目。复选框上没有唯一的 id,在查找特定标签/类组合时,我无法选择第一个项目以外的项目。是否有一些不是很明显的技巧来做到这一点。

【问题讨论】:

标签: coded-ui-tests


【解决方案1】:

这里有几个不同的选项:
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;
    }
}
  1. 您可以使用由Gautam Goenka 创建的these test utilities。就识别对象的内容并将其用于断言而言,它们为我创造了奇迹。不过,如果您没有任何有意义的方法来根据内容识别对象,那么这也无济于事。当所有其他方法都失败时,向 HTML 添加一些有用的标识属性。

【讨论】:

    猜你喜欢
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 1970-01-01
    • 2019-04-30
    • 2015-10-15
    • 2020-11-19
    • 1970-01-01
    相关资源
    最近更新 更多