【selenium+Python WebDriver API】之复选框顺序正选和顺序反选
from selenium import webdriver from selenium.webdriver.common.by import By import os,time driver = webdriver.Chrome() file_html = "file:///" + os.path.abspath("C:/Users/XXXXXX/Desktop/PY_file/html/checkbox/index.html") driver.get(file_html) #通过标签定位到每个input标签 # inputs = driver.find_elements(By.TAG_NAME,"input") #通过CSS定位每个标签 # checkbox1 = driver.find_elements(By.CSS_SELECTOR,"input[type='checkbox']") #通过XPATH定位每个标签 checkbox2 = driver.find_elements(By.XPATH,"//input[@type='checkbox']") #循环每个标签进行定位 for i in checkbox2: if i.get_attribute('type') == 'checkbox': i.click() time.sleep(1) # print(len(checkbox1))
#反选复选框 array = range(len(checkbox2),0,-1) for j in array: k = j-7 print(k) driver.find_elements(By.CSS_SELECTOR, "input[type='checkbox']").pop(k).click() time.sleep(1) #driver.quit()
不积跬步,无以致千里;不集小流,无以成江海。
如转载本文,请还多关注一下我的博客:https://www.cnblogs.com/Owen-ET/;
我的Github地址:https://github.com/Owen-ET————————————
无善无恶心之体, 有善有恶意之动, 知善知恶是良知, 为善去恶是格物。