python selenium笔记二登录(封装到单独脚本)

1、public.py(登陆注销脚本)

class Login():
    def user_login(self, browser):
        browser.find_element_by_id("account").clear()
        browser.find_element_by_id("account").send_keys("root")
        browser.find_element_by_id("cipher").clear()
        browser.find_element_by_id("cipher").send_keys("123")
        browser.find_element_by_id("login-btn").click()
    def user_logout(self, browser):
        browser.find_element_by_id("logoutSpan").click()

2、test.py(调用脚本)

from selenium import webdriver
from public import Login
import time
browser = webdriver.Firefox()
browser.get("http://xxxxxxxxxxx")
Login().user_login(browser)  #调用登录模块
time.sleep(8)
Login().user_logout(browser) #调用注销模块

 

你可能感兴趣的:(python selenium笔记二登录(封装到单独脚本))