多选框
# 随机选择多选框
# 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"#垂直滚动 px driver.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: if not box.is_selected(): box.click()