O'Reilly logo

Selenium Essentials by Prashanth Sams

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Select functions

A Select function allows you select or deselect values from a drop-down box or a radio button. It includes a list of Selenium API methods to work with select boxes that contain the <select></select> tags. These functions interact with the UI comboboxes to select options.

Select select = new Select(driver.findElement(By.locatorType("path")));

Some helpful snippets using select functions are given below:

  • The selectByIndex(index) method selects an option using the index value. The following is the syntax for this function:
    select.selectByIndex(index);

    Let's get into the bookstore and select a product from a drop-down list. Here, we select the products at the top of the options list using the selectByTndex() method:

    driver.get("http://www.barnesandnoble.com/"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required