select标签的下拉框
下拉框的选中
from selenium import webdriver#导包 from time import * from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.support.select import Select driver=webdriver.Chrome()#生成一个谷歌浏览器的操作对象 driver.get('http://公司禅道ip/zentao/company-browse.html') driver.find_element_by_class_name('form-control').send_keys('用户名')#禅道账号 driver.find_element_by_xpath('//*[@id="login-form"]/form/table/tbody/tr[2]/td/input').send_keys("密码")#禅道密码 driver.find_element_by_id('submit').click()#点击登录 id_elment='field4' WebDriverWait(driver,10,1).until(EC.visibility_of_element_located((By.ID,id_elment))) a=Select(driver.find_element_by_id('field4'))#定位select下拉框的位置 a.select_by_index(1)#通过索引定位,第一个为0 sleep(2) a.select_by_visible_text('用户名')#通过可见文本查找
下拉框的取消选中
a.deselect_by_index(1) a.deselect_by_visible_text('用户名')
非select标签的下拉框
后续更新