selectByAttribute
Select option with a specific value.
Usage
$(selector).selectByAttribute(attribute, value)
Parameters
Name | Type | Details |
---|---|---|
attribute | String | attribute of option element to get selected |
value | String , Number | value 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 name="someName5" value="someValue5">seis</option>
</select>
selectByAttribute.js
it('Should demonstrate the selectByAttribute command', async () => {
const selectBox = await $('#selectbox');
const value = await selectBox.getValue();
console.log(value); // returns "someValue0"
await selectBox.selectByAttribute('value', 'someValue3');
console.log(await selectBox.getValue()); // returns "someValue3"
await selectBox.selectByAttribute('name', 'someName5');
console.log(await selectBox.getValue()); // returns "someValue5"
});
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 name="someName5" value="someValue5">seis</option>
</select>
selectByAttribute.js
it('Should demonstrate the selectByAttribute command', () => {
const selectBox = $('#selectbox');
const value = selectBox.getValue();
console.log(value); // returns "someValue0"
selectBox.selectByAttribute('value', 'someValue3');
console.log(selectBox.getValue()); // returns "someValue3"
selectBox.selectByAttribute('name', 'someName5');
console.log(selectBox.getValue()); // returns "someValue5"
});
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.