Home > Blockchain >  check if all checkbox are unchecked on cypress
check if all checkbox are unchecked on cypress

Time:09-09

I have dynamic checkboxes (anything from 1-20 checkboxes). I want to check if all checkboxes are unchecked.

I have tried serval ways without any success.

//is true even if it is checked
cy.get('[type="checkbox"]').not("checked");

cy.get('[type="checkbox"]').should('have.attr', 'checked', false)

CodePudding user response:

I believe the issue is coming from the fact that your .get() should yield multiple checkboxes, but you're then using a singular assert on it. Switching to using .each() to iterate through each yielded checkbox should work better.

cy.get('[type="checkbox"]').each(($el) => {
  cy.wrap($el).should('have.attr', 'checked', false)
});

CodePudding user response:

The checked attribute does not have a true/false value. It's either present or absent.

This should work:

cy.get('[type="checkbox"]').should('not.be.checked')        // checks multiple
  • Related