# 對操作對象封裝
class BasePage:
driver = webdriver.Chrome()
# 訪問URL
def visit(self, url):
self.driver.get(url)# 元素定位
def locator(self, loc):
return self.driver.find_element(*loc)# 輸入
def input(self, loc, txt):
self.locator(loc).send_keys(txt)
# 點擊
def click(self, loc):
self.locator(loc).click()# 等待
def wait(self, time):
sleep(time)# 關(guān)閉
def close(self):
self.driver.quit()
# 對文本對象封裝
class SearchPage(BasePage):
url = 'http://www.baidu.com'# 定位百度輸入框
search_input = (By.NAME, 'wd')# 定位百度一下按鈕
search_button = (By.ID, 'su')# 封裝實現(xiàn)業(yè)務(wù)流程的函數(shù)
def search(self, txt):
self.visit(self.url)
self.wait(2)
self.input(self.search_input, txt)
self.wait(2)
self.click(self.search_button)
# 普通數(shù)據(jù)驅(qū)動
class Case(unittest.TestCase):
def test_search
文章來源地址http://www.zghlxwxcb.cn/news/detail-530363.html
文章來源:http://www.zghlxwxcb.cn/news/detail-530363.html
到了這里,關(guān)于python selenium 實現(xiàn)UI自動化POM設(shè)計模式的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!