Reputation: 171
I have to click a right arrow button while is enabled on the page.
This is my code:
var sig = element(by.id('#right_button'));
sig.isEnabled().then(function (result) {
while (result) {
sig.click();
return sig;
}
}
It only clicks two times, and I need clicking while element is enabled. How can I do?
Upvotes: 3
Views: 1791
Reputation: 6962
Make sure that your element is on the DOM even before you start executing the loop as the loops get executed much more faster than we think. Probably waiting for an element to load before clicking on it should do the trick. Or instead using function calls, is the best approach to it. Here's how you can do it -
var EC = protractor.ExpectedConditions;
var sig = element(by.id('#right_button'));
(function clickIt(){
browser.wait(EC.presenceOf(sig), 2000).then(function(){
sig.isEnabled().then(function (enabled) {
if(enabled){
sig.click().then(function(){
clickIt.call();
});
}
});
});
})();
Hope it helps.
Upvotes: 0
Reputation: 171
Solved this way:
var sig = element(by.id('#right_button'));
reclick = function (sig) {
sig.isEnabled().then(function (result) {
while (result) {
sig.click();
return reclick(sig);
}
});
};
reclick(sig);
Upvotes: 2