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 theindexvalue. 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/"); Select select = new Select(driver.findElement(By.id("quick-search-1-category"))); select.selectByIndex(1); select.selectByIndex(2);The
selectByValue(value)method selects an option usingvaluein the string format...