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

标签 javascript angularjs automated-tests protractor ng-bind

我正在使用 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/

相关文章:

javascript - 有没有办法制作一个带有 3 个透明框的实心 div?

javascript - 简写 if 语句总是返回 true

javascript - ng-class 在满足条件后不立即设置类

android - 使用 Appium 和 WebdriverIO 测试移动应用程序 : "No route found for/session"

javascript - react 表单钩子(Hook)如何验证选择选项

javascript - 如何在 reactJS 中使用 AngularJS 指令

javascript - 将表达式分配给变量并在 ng-class 中使用?

python - 如何在 python 中使用 selenium webdriver 滚动网页?

visual-studio-2010 - 手动编写编码的 UI 测试

javascript - 仅在单击按钮时运行功能