selenium定位下拉框及选择
# 打开Chrome浏览器
driver = webdriver.Chrome("chromedriver.exe")
# 浏览器访问html地址
driver.get("https://www.ihchina.cn/project.html")
time.sleep(5)
# 根据select下拉框的class定位,获取元素列表
select = driver.find_elements_by_class_name("select-native")[0]
# 获取select的所有选项
options_list = Select(select).options
for option in options_list:
print(option.text) # 打印每个选项的文本值
Select(select).select_by_index(0)
# 获取当前选中的下拉框中的选项
first = Select(select).first_selected_option.text
print("当前选中的下拉框:", first)
driver.quit()
运行上面的代码,不报错,就是option.text和first值为空。
而且按F12的时候“全部”这个选择没有出现在option当中
查看源代码,发现“全部”出现在了li标签里面。但是我需要选择“全部”这个选项,该怎么解决啊