前言:确认是否是select下拉框,可以到select标签下有option这种选项就是标准的select下拉框
# 用代码操作select下拉框
from selenium import webdriver
import time
from selenium.webdriver.support.select import Select # 导入select类
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("http://49.xxx.xx.xx:8000/user/")
time.sleep(3)
# 点击意见反馈
driver.find_element_by_link_text('[意见反馈]').click()
time.sleep(3)
driver.switch_to.frame(0)
# 第一种 选下拉框的选项 by_value
# s = driver.find_element_by_name("subject")
# Select(s).select_by_value("提BUG")
# time.sleep(3)
# # 第二种 visible_text
# s = driver.find_element_by_name("subject")
# Select(s).select_by_visible_text("提BUG")
# time.sleep(3)
# 第三种 index 索引从0开始
s = driver.find_element_by_name("subject")
Select(s).select_by_index(2)
time.sleep(3)
driver.quit()