我正在使用 Protractor 来测试 Angular ,我想使用绑定(bind)选择器获取一个值,并且获得 div 的所有内容。
<div class="table-header">
<span>{{::strategyCtrl.accountLabel | translate}}</span>
{{::strategyCtrl.accountIdValue}}
</div>
例如:
element(by.binding('strategyCtrl.strategyValue'));
将返回 strategyCtrl.accountLabel
和 strategyCtrl.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/