I tried below code but its still trying to click the button even if its disabled and the test is getting failed.
cy.get('button').should('not.be.disabled').click()<br>
cy.get('button').should('be.enabled').click()
I tried below code but its still trying to click the button even if its disabled and the test is getting failed.
cy.get('button').should('not.be.disabled').click()<br>
cy.get('button').should('be.enabled').click()
You can use the jQuery disabled-selector to achieve this. Your code should look like:
cy.get('button').then(($btn) => {
if ($btn.is(":disabled")) {
return
} else {
cy.wrap($btn).click()
}
})
I suggest invoke attribute:
cy.get('button')
.invoke('attr', 'disabled')
.then(disabled =>{
disabled ? cy.log('buttonIsDiabled') : cy.get('button').click()
})
© 2022 - 2024 — McMap. All rights reserved.
cy.get('button').then(($btn) => { if ($btn.is(":disabled")) { return } else { cy.wrap($btn).click() } })
– Hebdomad