mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-21 14:41:00 -06:00
3.3 KiB
3.3 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| select | true |
Select an option within a <select> DOM element.
The following events are fired during select: mousedown, focus, mouseup, click
| Returns | the new DOM element(s) found by the command. |
| Timeout | cy.select will retry for the duration of the defaultCommandTimeout or the duration of the timeout specified in the command's options. |
cy.select( text )
Select an option within a <select> element based on the text content of the option.
cy.select( value )
Select an option within a <select> element based on the value of the option.
cy.select( texts )
Select multiple options within a <select> element based on the text of the option.
cy.select( values )
Select multiple options within a <select> element based on the value of the option.
Options
Pass in an options object to change the default behavior of cy.select.
cy.select( text, options ) cy.select( value, options ) cy.select( array, options )
| Option | Default | Notes |
|---|---|---|
force |
false |
Forces select, disables error checking prior to select |
interval |
50 |
Interval which to retry a select |
timeout |
defaultCommandTimeout |
Total time to retry the select |
log |
true |
whether to display command in command log |
Text Usage
Select the option with the text apples
<select>
<option value="456">apples</option>
<option value="457">oranges</option>
<option value="458">bananas</option>
</select>
// returns <option value="456">apples</option>
cy.get('select').select('apples')
Value Usage
Select the option with the value "456"
<select>
<option value="456">apples</option>
<option value="457">oranges</option>
<option value="458">bananas</option>
</select>
// returns <option value="456">apples</option>
cy.get('select').select('456')
Texts Usage
Select the options with the texts "apples" and "bananas"
<select multiple>
<option value="456">apples</option>
<option value="457">oranges</option>
<option value="458">bananas</option>
</select>
cy.get('select').select(['apples', 'bananas'])
Values Usage
Select the options with the values "456" and "457"
<select multiple>
<option value="456">apples</option>
<option value="457">oranges</option>
<option value="458">bananas</option>
</select>
cy.get('select').select(['456', '457'])
Command Log
Select the option with the text "Homer Simpson"
cy.get('select').select('Homer Simpson')
The commands above will display in the command log as:
When clicking on select within the command log, the console outputs the following: