封装
一。分装的意义
封装是为了偏于管理代码,提高代码的效率,减少冗余
二。直接上代码
PS:目前在学习自动化,肯定有很多地方不成熟,慢慢随着学习来完善
# coding=utf-8
from selenium import webdriver
from common.page import PageLogin #路径
class Case():
loc_input=("id","kw")
def login(self):
driver=webdriver.Chrome()
driver.get("http://www.baidu.com")
#driver.find_element_by_id("kw).send_keys("python") #两种写法相同
self.sendKeys(loc_input,"python")
封装函数
# coding=utf-8 from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.by import By class PageLogin(): def findElement(self,locator): ele=WebDriverWait(driver,30).until(lambda x :x.find_elemnt(*locator)) return ele def sendKeys(self,locator,text): ele=self.findEelement(locator) ele.send_keys(text)