I need to select an element from the below drop-down menu.
Select
jumbo fruit 1
jumbo fruit 2
jumbo fruit 3
jumbo fruit 4
jumbo fruit 5
jumbo fruit 6
I have tried using this code,
driver = webdriver.Firefox()
driver.find_element_by_xpath("//select[@name='fruitType']/option[text()='jumbo fruit 4']").click()
but it returned me with errors.
How can I accomplish the same.
解决方案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