How to check checkbox in repeater with protractor

僤鯓⒐⒋嵵緔 提交于 2019-12-23 04:03:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!