Sander Lepik Sander Lepik - 17 days ago 6
AngularJS Question

How to filter out enabled buttons in Protractor?

I have a table with 20 buttons - half of them are disabled and th other half is enabled. Is it possible to filter out the enabled buttons and click all of them in for loop? (elements that I want to click -> class="fa fa-check")
I have problem with filtering disabled buttons.

Disabled buttons have attribute 'disabled' with value 'disabled'. This is the only difference between enabled and disabled buttons.

for (var i = 0; i < numberOfRows; ++i) { //numberOfRows
var button = element.all(by.repeater('tulemus in noue')).get(i);
button.getAttribute('disabled').then(function(status) {
if (I dont know how to verify the right status) {
$$('.fa-check').get(i).click();
console.log('enabled element clicked');
} else {
console.log(status);
console.log('element is disabled');
}
});
}


HTML code for two buttons

Answer

You can use each() to iterate the on array elements rather using for loop in javascript. You can follow the below code:

   element.all(by.repeater('tulemus in noue')).each(function(button,index){
            button.getAttribute('disabled').then(function(status) {
                if(!status){
                  button.click();//click if button is enabled
                 }
               else {
                    console.log(status);
                    console.log('element is disabled');
                }
            });
        });
Comments