I have two buttons. If one button has class disable than other hasn't. Now I want to check that if first button has class disable than I need to click on second button and vice-versa.
I am trying with below code but it is returning every time true. Disable class is added dynamically depends on condition.
if (expect(element(by.css('ul#menu [data-selector="holdInventory"]'))
.getAttribute('class')).toEqual('disabled')) {
console.log('has class');
} else {
console.log('has not class');
}
Any help will appreciated.
In protractor everything is a promise. So in order to perform an operation you need to resolve it first and then validate the class value. Also you cannot use equal because an element can be associated with multiple classes so you need to make use of includes instead.
var btn1 = element(by.css('ul#menu [data-selector="holdInventory"]'));
btn1.getAttribute('class')).then(function(cls) {
if(cls.includes('disabled')) {
btn1.click();
} else {
btn2.click();
}
});