批量重置密码
#导入各种包 from selenium import webdriver#浏览器 from selenium.webdriver.common.by import By#选择器 from selenium.webdriver.support import expected_conditions as EC#等待条件 from selenium.webdriver.support.wait import WebDriverWait#等待 from selenium.webdriver.common.keys import Keys#键盘 from selenium.common.exceptions import NoSuchElementException,StaleElementReferenceException,ElementNotVisibleException,TimeoutException,WebDriverException#各种错误类型 import time#计时器 def login(): url='https:///login.html' global dr dr=webdriver.Chrome() dr.maximize_window() dr.get(url) try: dr.switch_to.frame('wx-login') print('查找内嵌iframe!') except: print('查找内嵌iframe失败!') return try: em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'div.codelogin-bto>span'))) em.click() print('单击平台账号密码登录!') except: print('单击平台账号密码登录失败!') return try: em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'input[placeholder="请输入平台帐号"]'))) em.send_keys('') print('输入账号!') except: print('输入账号失败!') return try: em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'input[placeholder="请输入平台密码"]'))) em.send_keys('') print('输入密码!') except: print('输入密码失败!') return #class="el-button.el-button--primary" try: em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'button.el-button.el-button--primary'))) em.click() print('单击登录!') except: print('单击登录失败!') return #p:nth-child(2) try: em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'#MenuList a:nth-child(6)'))) em.click() print('单击去管理!') except: print('单击去管理失败!') return try: dr.switch_to.window(dr.window_handles[len(dr.window_handles)-1]) #dr.switch_to.window(dr.window_handles[0]) print('跳转到新页面!') except: print('跳转到新页面失败!') return time.sleep(2) # .accordion.dwz-accordion div:nth-child(5) try: em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'#sidebar div:nth-child(3) div:nth-child(5)'))) em.click() print('单击账号管理!') except: print('单击账号管理失败!') return time.sleep(1) #ClassManagement_Manage try: em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'[rel="ClassManagement_Manage"]'))) em.click() print('单击查看学生账号!') except: print('单击查看学生账号失败!') return time.sleep(1) #首页处理 btns=dr.find_elements_by_css_selector('a.button') print(len(btns)) for i in range(25): #break dr.find_elements_by_css_selector('a.button')[i].click() time.sleep(1) dr.find_element_by_css_selector('#alertMsgBox>div.alertContent>div>div.toolBar>ul>li>a>span').click() time.sleep(1) dr.find_element_by_css_selector('#alertMsgBox>div.alertContent>div>div.toolBar>ul>li>a>span').click() time.sleep(1) #下一页处理 while(1): #break if 'disabled' in dr.find_element_by_css_selector('li.j-next').get_attribute('class'): print('已经是最后一页') break try: dr.find_element_by_css_selector('li.j-next').click() time.sleep(2) btns=dr.find_elements_by_css_selector('a.button') print(len(btns)) for i in range(25): dr.find_elements_by_css_selector('a.button')[i].click() time.sleep(1) dr.find_element_by_css_selector('#alertMsgBox>div.alertContent>div>div.toolBar>ul>li>a>span').click() time.sleep(1) dr.find_element_by_css_selector('#alertMsgBox>div.alertContent>div>div.toolBar>ul>li>a>span').click() time.sleep(1) except: continue dr.execute_script('alert("所有人密码重置已经完成!");') if __name__ == '__main__': login()