python_批量修改密码综评

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.support.ui import Select
from selenium.common.exceptions import NoSuchElementException,StaleElementReferenceException,ElementNotVisibleException,TimeoutException,WebDriverException
import time
import os
import sys

dic={}
fp='data.txt'
with open(fp,'r') as file_object:
    lines=set(file_object.readlines())
for index,line in enumerate(lines):
    oneline=line.strip()
    if "=" in oneline:
        acc=oneline.split('=')[0]
        password=oneline.split('=')[1]
        dic[acc]=password
        #print(acc+' '+password)

home=''
print('>>>>请您在10秒内手动输入验证码,单击登陆!\n')
dr=webdriver.Chrome()
dr.get(home)

dr.switch_to.frame('iFrame1')
user=dr.find_element_by_name('j_username')
user.send_keys('')
pswd=dr.find_element_by_name('j_password')
pswd.send_keys('')

login=dr.find_element_by_class_name('go-login')
login.click()

time.sleep(10)
dr.switch_to.frame('iframepage')

#选择年份 和班级
gradestr=''
slt=dr.find_element_by_id('njQuery')
slt.click()
time.sleep(2)
selector=Select(slt)
selector.select_by_visible_text(gradestr)
#selector.select_by_value(gradestr)
time.sleep(2)


classstr=''
slt=dr.find_element_by_id('bjQuery')
slt.click()
time.sleep(2)
selector=Select(slt)
selector.select_by_visible_text(classstr)
#selector.select_by_value(classstr)
time.sleep(2)

#移动焦点 作一次无意义单击 取消下拉框的选中状态
op=dr.find_element_by_xpath('//th[@class="sorting_disabled text-left"]')
op.click()
time.sleep(1)

query=dr.find_element_by_xpath('//*[@id="usersTable"]/tbody/tr[3]/td[2]/button[1]')
query.click()
time.sleep(2)

chks=dr.find_elements_by_xpath('//input[@name="checkUid"]')
print(len(chks))
pageindex=1
while True:
    n=0
    for k in dic.keys():
        try:
            chk=dr.find_element_by_xpath('//input[@value='+k+']')
            n=n+1
        except:
            continue
            time.sleep(1)
        acc=k#chk.get_attribute("value")    print(acc)
        newpass=dic[acc]
        print('正在初始化 第'+str(pageindex)+'页 第'+str(n)+'个学生的密码!')
        print(newpass)
        chk.click()
        modify=dr.find_element_by_xpath('//*[@id="infoBtnDiv"]/button[3]')
        modify.click()
        time.sleep(2)
        inputnew=dr.find_element_by_xpath('//*[@id="pd"]')
        inputnew.send_keys(newpass)
        time.sleep(2)
        save=dr.find_element_by_xpath('//*[@id="saveChange"]')
        save.click()
        time.sleep(2)
        confirm=dr.find_element_by_xpath('//button[text()="确定"]')
        confirm.click()
        time.sleep(2)

        ok=dr.find_element_by_xpath('//button[text()="OK"]')
        ok.click()
        time.sleep(2)
        
        nextpage=dr.find_element_by_xpath('//a[text()='+str(pageindex)+']')
        nextpage.click()
        time.sleep(3)

        
        if n==10:
            n=0
            pageindex=pageindex+1

        print(dr.title)
    #dr.switch_to.frame('iframepage')
    if pageindex==7:
        break
print('modify student password')

猜你喜欢

转载自www.cnblogs.com/nextseven/p/11101989.html
今日推荐