gpt4 book ai didi

javascript - Protractor 中的绑定(bind)选择器捕获整个 div 而不是仅捕获值

转载 作者:行者123 更新时间:2023-11-27 23:47:53 25 4
gpt4 key购买 nike

我正在使用 Protractor 来测试 Angular ,我想使用绑定(bind)选择器获取一个值,并且获得 div 的所有内容。

<div class="table-header">
<span>{{::strategyCtrl.accountLabel | translate}}</span>
{{::strategyCtrl.accountIdValue}}
</div>

例如:

element(by.binding('strategyCtrl.strategyValue'));

将返回 strategyCtrl.accountLabelstrategyCtrl.accountIdValue 的值。

如何才能只获取strategyCtrl.accountIdValue的值。

最佳答案

尝试使用by.exactBinding Protractor 元素查找器来检查精确的绑定(bind)值。方法如下 -

element(by.exactBinding('strategyCtrl.accountIdValue'));

如果它仍然返回两个值,那么您可以使用字符串函数来获取该元素查找器返回的第二个字符串值。这是一个例子 -

element(by.binding('strategyCtrl.accountIdValue')).getText()
.then(function(text){
text.substring(text.indexOf(' ')); //assuming there is a space between the returned strings
});

希望有帮助。

关于javascript - Protractor 中的绑定(bind)选择器捕获整个 div 而不是仅捕获值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32993422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com