How to select a drop-down menu value in Selenium using Python?

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

For example:

Choose your fruits: Banana Mango 1. First I have to click on it. I do this:

inputElementFruits = driver.find_element_by_xpath(“//select[id=‘fruits’]”).click()

  1. After that I have to select the good element, lets say Mango.

I tried to do it with inputElementFruits.send_keys(...) but it did not work.

from selenium import webdriver b = webdriver.Firefox() b.find_element_by_xpath(“//select[@name=‘element_name’]/option[text()=‘option_text’]”).click()

1 Like