案例:网站模拟登录

# coding=utf-8

from selenium import webdriver

import time
# 如果没有在环境变量指定PhantomJS位置
driver = webdriver.PhantomJS(executable_path=r'/Users/loaderman/Documents/phantomjs-2.1.1-macosx/bin/phantomjs')
driver.get("http://192.168.0.195:8080/web/index.html")

# 输入账号密码
driver.find_element_by_name("username").send_keys("admin")
driver.find_element_by_name("password").send_keys("admin")

# 模拟点击登录
driver.find_element_by_xpath("//button[@class='layui-btn layui-btn-fluid']").click()

# 等待3秒
time.sleep(3)

# 生成登陆后快照
driver.save_screenshot("login.png")

with open("login.html", "w") as file:
    file.write(driver.page_source)

driver.quit()

  登入快照显示;

 

posted on 2019-11-30 16:32  LoaderMan  阅读(779)  评论(0编辑  收藏  举报

导航