| title | check |
|---|
Check checkbox(es) or radio(s).
{% note warning %}
This element must be an <input> with type checkbox or radio.
{% endnote %}
.check()
.check(value)
.check(values)
.check(options)
.check(value, options)
.check(values, options){% fa fa-check-circle green %} Correct Usage
cy.get('[type="checkbox"]').check() // Check checkbox element
cy.get('[type="radio"]').first().check() // Check first radio element{% fa fa-exclamation-triangle red %} 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{% 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 | Description |
|---|---|---|
log |
true |
{% usage_options log %} |
force |
false |
{% usage_options force check %} |
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout .check %} |
{% yields same_subject .check %}
cy.get('[type="checkbox"]').check()cy.get('[type="radio"]').check()cy.get('#saveUserName').check()<form>
<input type="radio" id="ca-country" value="CA">
<label for="ca-country">Canada</label>
<input type="radio" id="us-country" value="US">
<label for="us-country">United States</label>
</form>cy.get('[type="radio"]').check('US')<form>
<input type="checkbox" id="subscribe" value="subscribe">
<label for="subscribe">Subscribe to newsletter?</label>
<input type="checkbox" id="acceptTerms" value="accept">
<label for="acceptTerms">Accept terms and conditions.</label>
</form>cy.get('form input').check(['subscribe', 'accept'])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.check() is an "action command" that follows all the rules {% url 'defined here' interacting-with-elements %}.
{% requirements checkability .check %}
{% assertions actions .check %}
{% timeouts actions .check %}
check the element with name of 'emailUser'
cy.get('form').find('[name="emailUser"]').check()The commands above will display in the Command Log as:
{% imgTag /img/api/check/check-checkbox-in-cypress.png "Command log for check" %}
When clicking on check within the command log, the console outputs the following:
{% imgTag /img/api/check/console-showing-events-on-check.png "console.log for check" %}
- {% url
.click()click %} - {% url
.uncheck()uncheck %}