Skip to main content

selectByVisibleText

Overview

Use the selectByVisibleText command to select an option by its displayed text.

Usage

await browser.$(selector).selectByVisibleText(text);

Command Parameters

NameTypeDescription
textString or NumberThe text (of the option) by which to select the option.

Usage Examples

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("should demonstrate the selectByVisibleText command", async ({ browser }) => {
const selectBox = await browser.$("#selectbox");
console.log(await selectBox.getText("option:checked")); // outputs: "uno"

await selectBox.selectByVisibleText("cuatro");
console.log(await selectBox.getText("option:checked")); // outputs: "cuatro"
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.