In my previous question, I encountered an issue with clicking a button until it becomes disabled. Initially, the solution was as follows:
var nextPage = function () {
if (element(by.css('[ng-click="vm.nextPage()"]')).isEnabled()) {
element(by.css('[ng-click="vm.nextPage()"]')).click();
nextPage(); // proceed to next page
}
else {
return; // button is disabled, reaching last page
}
}
However, I had to make some adjustments to the code and now it looks like this:
var nextPage = function() {
if (element(by.id('next')).isEnabled()) {
element(by.id('next')).click().then(function() {
browser.sleep(1000);
nextPage(); // proceed to next page
return;
});
} else {
return; // button is disabled, reaching last page
}
return;
}
Unfortunately, this modification resulted in infinite recursive calls, making it impossible to perform the next step. I tried removing the .then
function but then the code stopped working altogether. How can I correct this without causing endless recursion?