How to click an <option> element with WebDriver? How to click an <option> element with WebDriver? selenium selenium

How to click an <option> element with WebDriver?


Besides the correct Qwerky's answer, you can also do simple

driver.findElement(By.xpath("//select/option[@value='1']")).click();

This finds the option element with value='1' and clicks it, practically selecting it in the drop-down.

Both mine and Qwerky's solution are described and explained here, in the documentation.


This will select the option with value "1" in the select with id "order_unit_line_rate_806782_is_addenda_enabled".

Select select = (Select)webdriver.findElement(By.id("your id here"));select.selectByValue("1");

You can also select by index or text; see the docs.