Adam Bovien Adam Bovien - 1 year ago 1094
Python Question

Selenium - Python - drop-down menu option value

I need to select an element from a drop-down menu.

For example, open this:

<select id="fruits01" class="select" name="fruits">
<option value="0">Choose your fruits:</option>
<option value="1">Banana</option>
<option value="2">Mango</option>

  1. So first I have to click on it. I do this:

    inputElementFruits = driver.find_element_by_xpath("//select["id='fruits']).click()

(ok, it's opening the menu)

  1. And after I have to select the good element, lets say Mango. I try different thing with
    but it did not work.

Answer Source

Unless your click is firing some kind of ajax call to populate your list, you don't actually need to execute the click.

Just find the element and then enumerate the options, selecting the option(s) you want.

Here is an example:

from selenium import webdriver
b = webdriver.Firefox()

You can read more in: