Selenium - Python - drop-down menu option value

0
0

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>
</select>

  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 inputElementFruits.send_keys(...) but it did not work.
  • You must to post comments
0
0

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()
b
.find_element_by_xpath("//select[@name='element_name']/option[text()='option_text']").click()

You can read more in:

https://sqa.stackexchange.com/questions/1355/unable-to-select-an-option-using-seleniums-python-webdriver

  • 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