当前位置:首页 > Python教程 > python技巧

Selenium3+python自动化009- 多选框

多选框

# 随机选择多选框
# sports=driver.find_elements_by_name("sport")
# maxnum=len(sports)
# num=random.randint(0,maxnum-1)
# sports[num].click()

技术分享图片 技术分享图片
                #
                encoding=utf-8
                from selenium import webdriver
from time import sleep
import os

driver=webdriver.Chrome()
url=file:/// + os.path.abspath(os.path.dirname(os.getcwd()))+/html/注册A.html

driver.maximize_window()
driver.get(url)

scroll="document.documentElement.scrollTop=800"#垂直滚动 pxdriver.execute_script(scroll)

carCheckBox=driver.find_element_by_id(qcA)
carCheckBox.click()
sleep(2)
if carCheckBox.is_selected():
    carCheckBox.click()

checkBoxList=driver.find_elements_by_xpath(//input[@name="checkbox"])
for box in checkBoxList:
    ifnot box.is_selected():
        box.click()
View Code

原文:https://www.cnblogs.com/liunaixu/p/11089647.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐