问题
I am having difficulty checking a checkbox in an AngularJs repeater with protractor.
The model looks like this:
environments: [
{
name: 'Proof of Concept',
checked: false
},
{
name: 'Non-Production',
checked: false
},
{
name: 'Production',
checked: false
}
]
The view like this:
<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();
回答1:
And trying to check the checkbox like this but when i run the test it does not seem to check it:
That is because you are clicking the repeater item - the div
element, but need to click the input
child element instead, I suspect.
You can chain the .all()
and .element()
calls in a single expression:
this.environments.first().element(by.css("input[ng-model$=checked]")).click();
回答2:
Try using the below code to click the checkboxes.
var repeaterElement = element.all(by.repeater('environment in vm.assessment.environments'))
repeaterElement.then(function (ElementArray) {
for(i = 0; i < ElementArray.length; i++) {
ElementArray[i].all(by.tagName('input')).get(0).click();
browser.sleep(1000);
}
})
来源:https://stackoverflow.com/questions/37558845/how-to-check-checkbox-in-repeater-with-protractor