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>
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>
Share
Improve this question
edited Jan 25, 2016 at 12:55
Reporter
3,9365 gold badges35 silver badges49 bronze badges
asked Jan 25, 2016 at 11:48
Yaniv EfraimYaniv Efraim
6,7118 gold badges54 silver badges98 bronze badges
0
1 Answer
Reset to default 6First 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());