Select in Selenium WebDriver
The ‘Select’ class in Selenium WebDriver is used for selecting and deselecting the option in a dropdown. The objects of Select type can be initialized by passing the dropdown webElement as parameter to its constructor.
WebElement testDropDown = driver.findElement(By.id("testingDropdown"));
Select dropdown = new Select(testDropDown);
Selecting options from dropdown
There are three ways of selecting options from dropdown-
- selectByIndex – To select an option based on its index, beginning with 0.
dropdown.selectByIndex(3);
- selectByValue – To select an option based on its ‘value’ attribute.
dropdown.selectByValue("Database");
- selectByVisibleText – To select an option based on the text over the option.
dropdown.selectByVisibleText("Database Testing");