常用元素操作api之select下拉列表操作(八)

from selenium import webdriver
import time
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By
# 下拉框处理
driver = webdriver.Chrome()
driver.get('file:///E:/%E6%A1%8C%E9%9D%A2/selenium%E5%85%83%E7%B4%A0%E6%93%8D%E4%BD%9C%E7%BB%83%E4%B9%A0%E4%BE%8B%E5%AD%90/selenium%E6%BC%94%E7%A4%BA%E4%BE%8B%E5%AD%90/select.html')
driver.implicitly_wait(30)
# 有三种方式
# 1)普通元素识别方法
# driver.find_element_by_xpath('//*[@id="status"]/option[4]').click()
# 2)层级定位
# driver.find_element_by_id('status').find_element_by_xpath('//*[@id="status"]/option[4]').click()
# 3)创建一个select对象,将下拉框识别成一个元素,把元素转成Select对象
#再通过3中操作放啊发操作下拉了
select_wl = driver.find_element(By.ID,'status')
s=Select(select_wl)
time.sleep(2)
s.select_by_index(3) #t通过索引定位
time.sleep(2)
s.select_by_value('3') #通过过文本定位
time.sleep(2)
s.select_by_visible_text('初审通过')




原文地址:https://www.cnblogs.com/tingting-yang/p/13335842.html