top button

In Selenium WebDriver, how do you select an item from a drop-down menu?

+1 vote
10 views
posted Apr 25 by Arunkumaarts

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

A: We can select an item from the drop-down menu by Value, by Index or by Visible Text.

Example:

WebElement cars = driver.findElement(By.id("cars"));

Select car = new Select(cars)

//select by value
car.selectByValue("vo"); //this will select Volvo from drop-down

//select by index
car.selectByIndex(2); //this will select Saab

//select by visible text
car.selectByVisibleText("Audi") //this will select Audi

answer Apr 26 by Arun
...