python selenium 下拉框的选择
1、首先导入Select (S大写)
from selenium.webdriver.support.ui import Select
2、界面展示图
3、使用三种方法对下拉框元素定位(GZcontent().xs() 这个是我进行分层管理的路径,需要自己更换成想要的路径)
"""下面用三种方法对下拉列表进行选择""" # 通过index进行选择下拉列表的值(根据排列的位置进行选择) Select(GZcontent().xs()).select_by_index(1) # 选择下拉列表的15 time.sleep(2) # 通过value进行选择(通过列表中value的值进行选择) Select(GZcontent().xs()).select_by_value("2") # 选择下拉列表的20 time.sleep(2) # 通过选项文字进行选择 Select(GZcontent().xs()).select_by_visible_text("25") # 选择下拉列表的25 time.sleep(2)