【发布时间】:2020-09-07 17:55:13
【问题描述】:
我目前正在阅读有关 selenium 的文档。这部分docs 让我有点困惑。 Perticually 是基本页面的一部分。描述如下:
class BasePage(object):
"""Base class to initialize the base page that will be called from all pages"""
def __init__(self, driver):
self.driver = driver
但如果这被认为是所有类的父级。实例化驱动程序并将驱动程序的方法包装成更合适的代码不是这个类的责任吗?我的意思是:
class BasePage(object):
def __init__(self):
self.driver = webdriver.Firefox()
def findElementsByCss(self,selector):
return self.driver.find_element_by_css_selector(selector)
def visit(self,url):
return self.driver.get(url)
那么其他页面不需要知道驱动就可以了
class FrontPage(BasePage):
def searchForItem(self,item)
return findElementsByCss(".input").send_keys( "hey" )
所以现在访问首页并搜索项目非常简单。这是正确的想法还是我混淆了它?
【问题讨论】:
标签: python selenium pageobjects