W3cubDocs

/Cypress

uncheck

Uncheck checkbox(es).

Syntax

.uncheck()
.uncheck(value)
.uncheck(values)
.uncheck(options)
.uncheck(value, options)
.uncheck(values, options)

Usage

Correct Usage

cy.get('[type="checkbox"]').uncheck()   // Unchecks checkbox element

Incorrect Usage

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

Arguments

value (String)

Value of checkbox that should be unchecked.

values (Array)

Values of checkboxes that should be unchecked.

options (Object)

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

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 .uncheck() to resolve before timing out

Yields

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

Examples

No Args

Uncheck all checkboxes

cy.get(':checkbox').uncheck()

Uncheck element with the id ‘saveUserName’

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

Value

Uncheck the checkbox with the value of ‘ga’

cy.get('input[type="checkbox"]').uncheck(['ga'])

Values

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

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

Notes

Actionability

The element must first reach actionability

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

Rules

Requirements

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

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

Assertions

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

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

Timeouts

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

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

Command Log

Uncheck the first checkbox

cy.get('[data-js="choose-all"]').click()
  .find('input[type="checkbox"]').first().uncheck()

The commands above will display in the Command Log as:

Command Log uncheck

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

Console Log uncheck

History

Version Changes
0.6.12 Added option force
0.3.3 .uncheck() command added

See also

© 2017 Cypress.io
Licensed under the MIT License.
https://docs.cypress.io/api/commands/uncheck.html