Reputation: 6713
I have a simple checkbox which I would like to check, using protractor (AngularJS).
I tried:
$('.checkbox-class-name').click();
But it does not help. The selector is working (finding my element), but no luck with the click. I also tried:
it('should test something if checkbox is checked', function (done) {
myPage.navigate();
$('.checkbox-class-name').click().then(function() {
//expect something here
done();
})
});
But it does not work (it is getting inside the 'then' but if I pause the browser I see that the checkbox is not checked)
What am I doing wrong?
EDIT my HTML code:
<div ng-if="vm._getTermsAndConditionsFlag()">
<input class="checkbox-class-name" id="checkbox-name"
ng-model="vm.termsAndConditionsChecked" type="checkbox">
<label for="checkbox-name" >I agree to the terms & conditions</label>
</div>
Upvotes: 2
Views: 5837
Reputation: 474011
First of all, check if this is the only element matching the selector and you are actually locating the desired checkbox. Also, try moving to the element and then making a click:
var checkbox = $('.checkbox-class-name');
browser.actions().mouseMove(checkbox).click().perform();
Or, scroll into element's view:
browser.executeScript("arguments[0].scrollIntoView();", checkbox.getWebElement());
checkbox.click();
Or, click via JavaScript (do understand the implications though):
browser.executeScript("arguments[0].click();", checkbox.getWebElement());
Upvotes: 6