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()
05-11 16:12
查看更多