Selenium定位下拉选有三种写法,如下:
#引入Select
from selenium.webdriver.support.ui import Select
# 通过index进行选择,从1开始
Select(driver.find_element_by_name("priority")).select_by_index(1)
# 通过value进行选择
Select(driver.find_element_by_name("priority")).select_by_value("中")
# 通过选项文字进行选择
Select(driver.find_element_by_name("priority")).select_by_visible_text("普通")
#选择下拉选
select = driver.find_element_by_name("priority")
# 获取select里面的option标签,注意使用find_elements
options_list = select.find_elements_by_tag_name(‘option‘)
# 遍历option
for option in options_list:
#获取下拉框的value和text
print ("Value is:%s Text is:%s" %(option.get_attribute("value"),option.text))
#输入检索式选择框
# 先定位输入框输入关键字
driver.find_element_by_id(‘id‘).send_keys(‘紧急‘)
# 然后定位ul
ul = driver.find_element_by_css_selector(".ui-autocomplete-items")
# 最后定位里面所有值
li = ul.find_elements_by_tag_name(‘li‘)
# 选取想要的值
li[0].click() # 0代表选择第一个值
参考:https://www.jianshu.com/p/9c459b9cc5a9
原文:https://www.cnblogs.com/yanding/p/11636826.html