check

Improve this doc

Check checkbox(es) or radio(s).

This element must be an <input> with type checkbox or radio.

Syntax

.check()
.check(value)
.check(values)
.check(options)
.check(value, options)
.check(values, options)

Usage

Correct Usage

cy.get('[type="checkbox"]').check()       // Check checkbox element
cy.get('[type="radio"]').first().check()  // Check first radio element

Incorrect Usage

cy.check('[type="checkbox"]') // Errors, cannot be chained off 'cy'
cy.get('p:first').check()     // Errors, '.get()' does not yield checkbox or radio

Arguments

value (String)

Value of checkbox or radio that should be checked.

values (Array)

Values of checkboxes or radios that should be checked.

options (Object)

Pass in an options object to change the default behavior of .check().

Option Default Description
log true Displays the command in the Command log
force false Forces the action, disables waiting for actionability
timeout defaultCommandTimeout Time to wait for .check() to resolve before timing out

Yields

  • .check() yields the same subject it was given from the previous command.

Examples

No Args

Check all checkboxes

cy.get('[type="checkbox"]').check()

Check all radios

cy.get('[type="radio"]').check()

Check the element with id of ‘saveUserName’

cy.get('#saveUserName').check()

Value

Select the radio with the value of ‘US’

cy.get('[type="radio"]').check('US')

Values

Check the checkboxes with the values ‘ga’ and ‘ca’

cy.get('[type="checkbox"]').check(['ga', 'ca'])

Options

Check an invisible checkbox

You can ignore Cypress’ default behavior of checking that the element is visible, clickable and not disabled by setting force to true in the options.

cy.get('.action-checkboxes').should('not.be.visible') // Passes
  .check({ force: true }).should('be.checked')        // Passes

Notes

Actionability

The element must first reach actionability

.check() is an “action command” that follows all the rules defined here.

Rules

Requirements

  • .check() requires being chained off a command that yields DOM element(s).

  • .check() requires the element to have type checkbox or radio.

Assertions

  • .check() will automatically wait for the element to reach an actionable state.

  • .check() will automatically wait for assertions you've chained to pass.

Timeouts

  • .check() can time out waiting for the element to reach an actionable state.

  • .check() can time out waiting for assertions you've added to pass.

Command Log

check the element with name of ‘emailUser’

cy.get('form').find('[name="emailUser"]').check()

The commands above will display in the Command Log as:

Command log for check

When clicking on check within the command log, the console outputs the following:

console.log for check

See also