python automation ---- selenium automatically enter a user name and password to verify successful login and printed the wrong reasons

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_44846959/article/details/102740450

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 ( '// * [@ the above mentioned id = "App"] / Section / header / div / div [2] / div / div / span') text
IF element1 == username:
Print ( "Login successful The user name and password are "+ List1)
recode.write ( 'successful login, the user name and password are' + List1)
driver.back ()
the except:
driver.implicitly_wait (1)
ERROR_MESSAGE driver.find_element_by_xpath = (" / HTML / body / div [2] / div / div [2] / div [1] / the p-")
Print (" Login failed for user name and password are "+ list1 +" specific error message is: "+ error_message.text +" \ n-")
recode.write (" failed login user name and password are "+ list1 +" specific error message is: "+ error_message.text + '\ n-')
CURRENT_TIME The time.strftime = (" Y-% m% -% D-% of M_% S% H_ ", time.localtime (the time.time ()))
PIC_PATH = 'C: \ the Users \ Desktop \' + + CURRENT_TIME '.png'
driver.save_screenshot (PIC_PATH)
Continue
driver.back()
driver.close()
f.close()
recode.close()

Guess you like

Origin blog.csdn.net/weixin_44846959/article/details/102740450