发一个本网站后台登录的自动化代码

  • A+
所属分类:Python篇
刚写的,新鲜出炉
代码如下
#coding=utf8
from selenium import webdriver
import unittest
import time
import HTMLTestRunner
login_name = ""
login_passwd = ""
redstar = webdriver.Chrome()
current_time = time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime(time.time()))
# current_time1 = time.strftime("%Y-%m-%d", time.localtime(time.time()))
pic_path = 'd:\\app\\temp\\' + current_time +'.png'
print(pic_path)
time.sleep(5)
try:
    redstar.get("http://www.52soul.info/wordpress/wp-login.php")
    redstar.maximize_window()
    redstar.save_screenshot(pic_path)
    if u'登录 ‹ Py交易 — WordPress' == redstar.title:
        print (current_time+'浏览器加载成功,验证通过.')
        redstar.find_element_by_id("user_login").clear()
        redstar.find_element_by_id("user_login").send_keys(login_name)
        redstar.find_element_by_id("user_pass").send_keys(login_passwd)
        redstar.find_element_by_id("wp-submit").click()
        if redstar.find_element_by_id("wp-admin-bar-site-name").is_displayed():
            print(current_time+"管理界面已打开,验证通过")
        else:
            print(current_time+"管理界面未打开,验证失败")
    else:
        print (current_time+'异常异常,验证失败')
except Exception as e:
     print (current_time+"浏览器加载失败,验证失败,请检查相关原因", format(e))
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: