如何使用pyselenium选择选择元素中的选项?

问题描述:

这似乎并不工作:如何使用pyselenium选择选择元素中的选项?

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

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

你必须找到合适的选项元素.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() 
+0

注意,如果元素没有找到XPath的似乎看透了所有的选项元素挂,所以一个最好的可能环路丑陋的方式 – Claudiu