How to select an item from a dropdown list using Selenium WebDriver with java?

0
0

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.

  • You must to post comments
0
0

Use –

new Select(driver.findElement(By.id("gender"))).selectByVisibleText("Germany");

Of course, you need to import org.openqa.selenium.support.ui.Select;

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website