Selecting a Single Option From a Select List

Learn how you can interact with a single select list using Selenium.

Select an option by text

Typically on a web page in a browser, we see the label of a select list. With the help of this label, we can select an option from a select list in Selenium as:

driver.findElement("car_make")).sendKeys("Volvo (Sweden)");  

// or by partial text

Here, the sendKey() function is used to select an option from the select list.

However, note that writing such scripts in NodeJS is different from any other supported language. For instance, if we were to write the exact same thing in JAVA, we would do something like:

Select select = new Select(driver.findElement("car_make_select")));
select.selectByVisibleText("Volvo (Sweden)");

Although the latter approach is much more clear than the former, we don’t have any equivalent workaround in NodeJS.

Get hands-on with 1200+ tech skills courses.