selenium+Python WebDriver API之复选框顺序正选和顺序反选

Posted Owen_ET

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()

 


以上是关于selenium+Python WebDriver API之复选框顺序正选和顺序反选的主要内容,如果未能解决你的问题,请参考以下文章

Selenium WebDriver(Python)API

[python] python+selenium+webdriver

[python] python+selenium+webdriver

selenium webdriver (python)大全

python+selenium—webdriver入门

转载selenium+Python WebDriver之selenium的定位以及切换frame(iframe)