【问题标题】:How do I select options in a select element with pyselenium?如何使用 pyselenium 在选择元素中选择选项?
【发布时间】:2023-03-29 11:17:01
【问题描述】:

这似乎不起作用:

select_input = self.ff.find_element_by_name(select_name)
select_input.select_by_value(option_val)

但似乎select_by_value 将是最明显的选择。

【问题讨论】:

    标签: python selenium automation web-crawler


    【解决方案1】:

    你必须找到合适的选项元素和.click()它:

    select_input = self.ff.find_element_by_name(select_name)
    option = select_input.find_element_by_xpath("option[value=%s]" % option_val)
    option.click()
    

    【讨论】:

    • 请注意,如果找不到元素,xpath 似乎会挂起,所以最好可能会以丑陋的方式遍历所有选项元素
    猜你喜欢
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 2021-11-08
    • 2020-07-29
    • 2013-08-06
    • 1970-01-01
    相关资源
    最近更新 更多