如何在带有量角器的中继器中选中复选框 [英] How to check checkbox in repeater with protractor
问题描述
我很难在带有量角器的AngularJs中继器中选中一个复选框.
I am having difficulty checking a checkbox in an AngularJs repeater with protractor.
模型如下:
environments: [
{
name: 'Proof of Concept',
checked: false
},
{
name: 'Non-Production',
checked: false
},
{
name: 'Production',
checked: false
}
]
这样的视图:
<div class="checkbox" ng-repeat="environment in vm.assessment.environments">
<label><input type="checkbox" ng-model="vm.assessment.environments[$index].checked" ng-click="vm.checkboxChanged()" ng-required="!vm.someChecked">{{environment.name}}</label>
</div>
像这样使中继器进入量角器:
Am getting the repeater in protractor like so:
this.environments = element.all(by.repeater('environment in vm.assessment.environments'));
并尝试像这样检查复选框,但是当我运行测试时似乎没有对其进行检查:
And trying to check the checkbox like this but when i run the test it does not seem to check it:
this.environments.get(0).click();
推荐答案
并尝试像这样检查复选框,但是当我运行测试时似乎没有对其进行检查:
And trying to check the checkbox like this but when i run the test it does not seem to check it:
那是因为您单击的是转发器项-div
元素,但是我想需要单击input
子元素.
That is because you are clicking the repeater item - the div
element, but need to click the input
child element instead, I suspect.
您可以在单个表达式中链接 .all()
和.element()
调用:
You can chain the .all()
and .element()
calls in a single expression:
this.environments.first().element(by.css("input[ng-model$=checked]")).click();
这篇关于如何在带有量角器的中继器中选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!