<button _ngcontent-c21="" color="primary" mat-button="" class="mat-button 
mat-primary" ng-reflect-disabled="true" ng-reflect-color="primary" 
disabled=""><span class="mat-button-wrapper">

The above contains and element that can enable or disable the button depending on the user rights. I'm trying to create a test to verify whether the button is active/disabled depending on the logged in user. I'm trying to use


but I'm not sure how to get this to work with my 'get' element (see below)


Well this was embarrassingly simple


and this will allow me to check if buttons are disabled or not. Didn't even need to use the "expect" route.


The Cypress documentation shows examples how you can use should() to verify elements are enabled/disabled: https://docs.cypress.io/api/commands/should.html#Assert-the-checkbox-is-disabled


I recently found this code working in my case where I wanted to check if the element was enabled for next actions:

this.button().then(($btn) => {
  if ($btn.is("enabled")) {
    //do something
  } else {
    //do something else

// in cypress terms
    cy.get(':button').then((x) => {
      if (x.is("enabled")) {
        //do something if enabled
      } else {
        //do something else

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.