Reputation: 33
I am new to the world of automating tests on angular pages. The framework I am using is protractor, but I am clubbing it with cucumberjs.
I am trying to click on a radio button. This is how the element looks like in the DOM :-
<div>
<input class="ng-pristine ng-untouched ng-valid" type="radio" ng-click="setTestOrValid(p)" value="Valid" ng-model="p.testOrValidDisplay" name="341">
Valid
<input class="ng-pristine ng-untouched ng-valid" type="radio" ng-click="setTestOrValid(p)" value="Invalid" ng-model="p.testOrValidDisplay" name="342">
Invalid (Test/Junk)
</div>
Following is the function which I have written to be able to click on it :-
sut.browser.findElements(sut.by.css('[ng-click="setTestOrValid(p)"]')).then(function(elements){
for (i=0; i < elements.length; i++){
elements[i].getAttribute('value').then(function(value){
if (value == 'Invalid') {
elements[i].click();
}
})
}
});
The code above throws an error :-
TypeError: Cannot read property 'click' of undefined
Would you please help me with this?
Upvotes: 3
Views: 534
Reputation: 474001
You can get to your element in one go using a CSS selector:
var elm = $("input[type=radio][value=Invalid]");
elm.click();
Or, you can filter all radiobuttons by model and filter()
:
var elm = element.all(by.model("p.testOrValidDisplay")).filter(function(elm) {
return elm.getAttribute("value").then(function (value) {
return value === "Invalid";
});
}).first();
elm.click();
Upvotes: 2