Search code examples
angularjsseleniumprotractorangularjs-e2ee2e-testing

Can not click checkbox with element from by.repeater


For some reason I can not click a checkbox with by.repeater. There are no errors. When viewing the browser, the checkbox is simply not getting checked. Any ideas? I would like to stay with by.repeater if possible.

  this.modelChoices = function(rowNumber) {
    return element.all(by.repeater('model in vehicleCheckboxes.models'));
  } 

  checkboxes.modelChoices().get(0).click();

Solution

  • GIVEN:

    <div>
        <div class="input-group" ng-repeat="item in vm.dataFiles | filter:vm.query">
            <span class="input-group-addon">
                <input type="checkbox" ng-model="item.isChecked">
            </span>
            <label class="form-control">{{item.name}}</label>
        </div>
    </div>
    

    This is part of my e2e tests that might help you in a way. Note that I have my checkbox bound to "item.isChecked"

    it("should disable the create button when there are no checked items in the vm.dataFiles", function () {
        var dataFiles = element.all(by.repeater("item in vm.dataFiles"));
        var firstCheckbox = dataFiles.get(0).element(by.model("item.isChecked"));
        var btnCreate = element(by.id("btnCreate"));
    
        expect(btnCreate.isEnabled()).not.toBeTruthy();
        firstCheckbox.click();
        expect(btnCreate.isEnabled()).toBeTruthy();
        firstCheckbox.click();
        expect(btnCreate.isEnabled()).not.toBeTruthy();
    });