首页 > 代码库 > Python+selenium(11)脚本模块化&参数化

Python+selenium(11)脚本模块化&参数化

mail126.py脚本如下

from selenium import webdriverfrom time import sleepfrom model1 import Logindriver = webdriver.Chrome()driver.get("http://www.126.com")print("登录前")title = driver.titleprint("title:" + title)#调用登录l = Login(driver)#邮箱用户名需输入你自己的真实的126邮箱用户名,密码也需要是真实的l.login("邮箱用户名","邮箱密码")url = driver.current_urlprint("url:"+url)sleep(5)print("登陆后:")title = driver.titleprint("url:"+url)text = driver.find_element_by_id("spnUid").textprint("user name:"+text)#断言assert text == "邮箱用户名"

model1.py脚本如下

class Login():    def __init__(self,driver):        self.driver = driver    def login(self,username,password):        driver = self.driver        driver.switch_to.frame("x-URS-iframe")                driver.find_element_by_name("email").clear()        driver.find_element_by_name("email").send_keys(username)        driver.find_element_by_name("password").clear()        driver.find_element_by_name("password").send_keys(password)        driver.find_element_by_id("dologin").click()

 

Python+selenium(11)脚本模块化&参数化