Check enabled checkboxes

Watch this example in the video Check The Enabled Checkboxesopen in new window.

    <input type="checkbox" name="c1" disabled="disabled" />
    <label for="c1">I have a bike</label>
    <input type="checkbox" name="c2" />
    <label for="c2">I have a car</label>
    <input type="checkbox" name="c3" />
    <label for="c3">I have a boat</label>
li {
  list-style-type: none;

We can get all the checkboxes, filter out the disabled ones using the attribute selector, then click on each one via cy.clickopen in new window

// check all enabled checkboxes using multiple clicks
cy.get(':checkbox').not('[disabled]').click({ multiple: true })

Better: use the cy.checkopen in new window command


Best: use the jQuery :enabledopen in new window selector plus the cy.checkopen in new window command

// use the jQuery :checkbox + :enabled selectors
// and the cy.check command
// confirm the number of checked inputs
// using the jQuery :checked selector
cy.get(':checked').should('have.length', 2)

See also