python - 页面对象模型中的显式等待

时间:2015-10-09 06:28:40

标签: python selenium

如何使用显式等待的Page对象模式。这是我在名为test_page.py的文件中的测试用例的代码:

class TestPages(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('http://abcd.com')

    def test_login_button(self):
        MainPage(self.driver).wait_for_button()
        # do some more actions 

    def tearDown(self):
        self.driver.close()

这是在page.py

中定义页面的地方
class Page(object):

    def __init__(self, driver):
        self.driver = driver

    def find_element(self, *locator):
        return self.driver.find_element(*locator)

    def get_title(self):
        return self.driver.title

    def wait_for_element(self, *locator):
        return WebDriverWait(self.driver, 25).until(
            EC.visibility_of_element_located((*locator)))


class MainPage(Page):

    def wait_for_button(self):
        return self.wait_for_element(*MainPageLocators.login_here)

这里的locators.py是存储的定位器:

class MainPageLocators(object):
    logo = (By.CSS_SELECTOR, '.form > a > img')
    login_here = (By.CSS_SELECTOR, '.btn')

我收到此错误:

in wait_for_element
    EC.visibility_of_element_located(*locator))
TypeError: __init__() takes exactly 2 arguments (3 given)

所以我在(*locator)周围添加了括号:

现在上面的代码给出了语法错误。我该怎么办,我是python的新手。

0 个答案:

没有答案