I have element. And I need verify which class in this element and do something after that. How can I do it?
cy.get('element')
.should('have.class', 'Enabled')
.log('Enabled')
or
.log('Disabled')
I have element. And I need verify which class in this element and do something after that. How can I do it?
cy.get('element')
.should('have.class', 'Enabled')
.log('Enabled')
or
.log('Disabled')
Using a .then() function to yield the element found by cy.get(), and then using the JQuery function hasClass to determine if the yielded element has the Enabled class should work.
cy.get('element').then(($el) => {
cy.log($el.hasClass('Enabled') ? 'Enabled' : 'Disabled');
if ($el.hasClass('Enabled')) {
// some code
} else {
// some other code
}
})