Cypress: Unable to Detect 'disabled' Attribute in <a /> Tag

Created on 6 Dec 2019  路  5Comments  路  Source: cypress-io/cypress

Most helpful comment

I found this way cy.get('.ag-filter-select').should('have.attr', 'disabled', 'disabled') and it works.

All 5 comments

I think be.disabled relates to chaiJS
see: https://docs.cypress.io/guides/references/assertions.html#Chai-jQuery
And the official chaiJS docu refers to jquerys :disabled selector which does not check for the existence of the disabled attribute:

image

As you can see, the a tag is not supported by this assertion.

it goes deper actually

https://stackoverflow.com/questions/13955667/disabled-href-tag/13955695

Not cypress's fault at all. <a /> tag itself has no support for disabled, but it will still be represented in the DOM as an html attribute. A Cypress/Jquery assertion would be nice though, since additional logic can be built around it.

Im having the same issue with a div element

<div class="ag-filter-select" disabled="">

so Im using something like:

cy.get('.ag-filter-select').should('be.disabled');

Does anyone found a workaround?

I found this way cy.get('.ag-filter-select').should('have.attr', 'disabled', 'disabled') and it works.

I also had the same issue. cy.get().should('be.disabled') returned false when attr is disabled.

but it works in this way:

cy.get().should('have.attr', 'disabled');
cy.get().should('not.have.attr', 'disabled');
Was this page helpful?
0 / 5 - 0 ratings

Related issues

carloscheddar picture carloscheddar  路  3Comments

brian-mann picture brian-mann  路  3Comments

weskor picture weskor  路  3Comments

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments