Selenium WebDriver to select combo-box item?

Viewed 75797

We are using Selenium WebDriver and JBehave to run "integration" tests on our web-app. I have a method that will enter a value into a form input.

@When("I enter $elementId value $value")
public void enterElementText(final String elementId, final String value) {
    final WebElement webElement = webdriver.findElement(By.id(elementId));
    webElement.clear();
    webElement.sendKeys(value);
}

But when I try to use this to select an item in a drop-down list it (unsurprisingly) fails

java.lang.UnsupportedOperationException: You may only set the value of elements that are input elements

How do I select a value in the combo?

4 Answers
Related