selectByVisibleText
Select option with displayed text matching the argument.
Usage
$(selector).selectByVisibleText(text)
Parameters
Name | Type | Details |
---|---|---|
text | String , Number | text of option element to get selected |
Examples
- Asynchronous Mode
- Synchronous Mode
example.html
<select id="selectbox">
<option value="someValue0">uno</option>
<option value="someValue1">dos</option>
<option value="someValue2">tres</option>
<option value="someValue3">cuatro</option>
<option value="someValue4">cinco</option>
<option value="someValue5">seis</option>
</select>
selectByVisibleText.js
it('demonstrate the selectByVisibleText command', async () => {
const selectBox = await $('#selectbox');
console.log(await selectBox.getText('option:checked')); // returns "uno"
await selectBox.selectByVisibleText('cuatro');
console.log(await selectBox.getText('option:checked')); // returns "cuatro"
})
example.html
<select id="selectbox">
<option value="someValue0">uno</option>
<option value="someValue1">dos</option>
<option value="someValue2">tres</option>
<option value="someValue3">cuatro</option>
<option value="someValue4">cinco</option>
<option value="someValue5">seis</option>
</select>
selectByVisibleText.js
it('demonstrate the selectByVisibleText command', () => {
const selectBox = $('#selectbox');
console.log(selectBox.getText('option:checked')); // returns "uno"
selectBox.selectByVisibleText('cuatro');
console.log(selectBox.getText('option:checked')); // returns "cuatro"
})
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.