3.3 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| check | true |
Check checkbox(es) or radio(s).
Syntax
.check()
.check(value)
.check(values)
.check(options)
.check(value, options)
.check(values, options)
Usage
.check() requires being chained off another cy command that yields a DOM element of type checkbox or radio.
{% fa fa-check-circle green %} Valid Usage
cy.get('[type="checkbox"]').check() // Yields checkbox element
cy.get('[type="radio"]').first().check() // Yields first radio element
{% fa fa-exclamation-triangle red %} Invalid 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
{% fa fa-angle-right %} value (String)
Value of checkbox or radio that should be checked.
{% fa fa-angle-right %} values (Array)
Values of checkboxes or radios that should be checked.
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of .check().
| Option | Default | Notes |
|---|---|---|
interval |
16 |
Interval which to retry a check |
timeout |
defaultCommandTimeout |
Total time to retry the check |
force |
false |
Forces check, disables error checking prior to check |
log |
true |
whether to display command in command log |
Yields
.check() yields the DOM element from the previous command.
Timeout
.check will retry for the duration of the defaultCommandTimeout or the duration of the timeout specified in the command's options.
Examples
Check
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 value of '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 passing force: true in the .check() options.
cy
.get('.action-checkboxes').should('not.be.visible') // Passes
.check({force: true}).should('be.checked') // Passes
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:
When clicking on check within the command log, the console outputs the following: