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

前端 未结 3 639
悲哀的现实
悲哀的现实 2021-01-14 05:25

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


                        
    
提交评论

  • 2021-01-14 06:10

    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

    0 讨论(0)
  • 2021-01-14 06:29

    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()
    
    0 讨论(0)
  • 提交回复
    热议问题