from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import os,time
import unittest
driver = webdriver.Chrome()
driver.get(“http://xxxxxxxx/”)//输入相关网址
driver.maximize_window() # 浏览器最大化
f = open(“C:\Users\Desktop\user.txt”, “r”)//存入正确的路径
fr = f.readlines()
for list1 in fr:
try:
driver.refresh()
driver.find_elements_by_class_name(“el-input__inner”)[0].send_keys(list1.split(’,’)[0])
driver.find_elements_by_class_name(“el-input__inner”)[1].send_keys(list1.split(’,’)[1])
username = list1.split(’,’)[0]
recode = open(‘C:\Users\Desktop\recode.txt’, ‘a’,encoding=‘utf8’)
driver.implicitly_wait(1)
element1 = driver.find_element_by_xpath(’//*[@id=“app”]/section/header/div/div[2]/div/div/span’).text
if element1 == username:
print(“登录成功,用户名和密码分别为” + list1)
recode.write(‘登录成功,用户名和密码分别为’ + list1)
driver.back()
except:
driver.implicitly_wait(1)
error_message = driver.find_element_by_xpath("/html/body/div[2]/div/div[2]/div[1]/p")
print(“登录失败,用户名和密码分别为” + list1 + “具体错误信息为:” + error_message.text + “\n”)
recode.write(“登录失败,用户名和密码分别为” + list1 + “具体错误信息为:” + error_message.text + ‘\n’)
current_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
pic_path = ‘C:\Users\Desktop\’ + current_time + ‘.png’
driver.save_screenshot(pic_path)
continue
driver.back()
driver.close()
f.close()
recode.close()