Google News
logo
Selenium - Interview Questions
How to select value in a dropdown?
The value in the dropdown can be selected using WebDriver’s Select class.
 
Syntax :
 
selectByValue :
Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
selectByValue.selectByValue(“greenvalue”);
 
selectByVisibleText :
Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
selectByVisibleText.selectByVisibleText(“Lime”);
 
selectByIndex :
Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));
selectByIndex.selectByIndex(2);
Advertisement