量角器:如何使用 href 子字符串或 span 子字符串单击元素?
Protractor: How do I click on an element using the href substring or span substring?
以下几行是我希望能够使用量角器点击的元素的信息。
<hsx-nav-menu-group hsx-html-element> == [=10=]
<hsx-nav-menu-info>
<i hsx-html-element hsx-icon>
<svg>
<use xlink:href="#icon-so"></use>
</svg>
</i>
<span>Service Orders</span>
</hsx-nav-menu-info>
</div>
我已经能够通过 xpath 单击它,但我想找到并单击最好使用 href 子字符串或 span 子字符串的元素。
I wanted to locate and click the element preferably with the href substring or the span subtring
让我们使用 Service Orders
文本来创建定位器:
element(by.xpath("//hsx-nav-menu-info[span = 'Service Orders']"));
虽然这仍然是一个 XPath 表达式。
或者,您可以使用 filter()
:
$$("hsx-nav-menu-info").filter(function (useElm) {
return useElm.$("use").getAttribute("xlink:href").then(function (href) {
return href === "#icon-so";
});
}).first().click();
以下几行是我希望能够使用量角器点击的元素的信息。
<hsx-nav-menu-group hsx-html-element> == [=10=]
<hsx-nav-menu-info>
<i hsx-html-element hsx-icon>
<svg>
<use xlink:href="#icon-so"></use>
</svg>
</i>
<span>Service Orders</span>
</hsx-nav-menu-info>
</div>
我已经能够通过 xpath 单击它,但我想找到并单击最好使用 href 子字符串或 span 子字符串的元素。
I wanted to locate and click the element preferably with the href substring or the span subtring
让我们使用 Service Orders
文本来创建定位器:
element(by.xpath("//hsx-nav-menu-info[span = 'Service Orders']"));
虽然这仍然是一个 XPath 表达式。
或者,您可以使用 filter()
:
$$("hsx-nav-menu-info").filter(function (useElm) {
return useElm.$("use").getAttribute("xlink:href").then(function (href) {
return href === "#icon-so";
});
}).first().click();