I\'m writing protractor tests and like it, although sometimes seem to get caught up on something that seems as if it should be simple. For example, I want to loop through all o
els
is defined. What's not defined is x
.
The easy way to do it is:
var nominateButtons = element.all(by.buttonText('Nominate'));
var displayedButtons = nominateButtons.filter(function(elem) {
return elem.isDisplayed();
});
displayedButtons.first().click();
or
element.all(by.buttonText('Nominate')).
filter(function(elem) {
return elem.isDisplayed();
}).
first().
click();
EDIT, by the way, you shouldn't rely on this behavior (click first button of text 'Nominate') because it will lead to issues when you change your app. See if you can either select by ID, or select a more specific 'Nominate' like element(by.css('the section the nominate is under')).element(by.buttonText('Nominate'));
EDIT again: see Using protractor with loops for explanation