I need to select an element from the below drop-down menu.
From the official documentation:
from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_id('fruitType'))
# Now we have many different alternatives to select an option.
select.select_by_index(4)
select.select_by_visible_text("jumbo fruit 4")
select.select_by_value('4') #Pass value as string
Hi please simply use one line code it will work
// please note the if in case you have to select a value form a drop down with tag
// name Select then use below code it will work like charm
driver.find_element_by_id("fruitType").send_keys("jumbo fruit 4");
Hope it helps
you can iterate trough all options like this:
element = driver.find_element_by_xpath("//select[@name='fruitType']")
all_options = element.find_elements_by_tag_name("option")
for option in all_options:
print("Value is: %s" % option.get_attribute("value"))
option.click()