How can I select an item from a drop down list like gender (eg male, female) using Selenium WebDriver with Java?
I have tried this
WebElement select = driver.findElement(By.id("gender")); List<WebElement> options = select.findElements(By.tagName("Male")); for (WebElement option : options) { if("Germany".equals(option.getText())) option.click(); }
My above code didn't work.
Use -
new Select(driver.findElement(By.id("gender"))).selectByVisibleText("Germany");
Of course, you need to import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.Select;
1.4m articles
1.4m replys
5 comments
57.0k users