Does Webdriver support pagefactory for Python?

前端 未结 3 739
囚心锁ツ
囚心锁ツ 2021-02-15 23:18

I was reading about page objects and design patterns on the Webdriver project site and came across pagefactory. It doesn\'t look like the Webdriver for Python API includes page

3条回答
  •  日久生厌
    2021-02-15 23:53

    I have created a module called pageobject_support that implements PageFactory pattern in a pythonic way.

    With this module, Google Search page could be modelled as follows:

    from pageobject_support import cacheable, callable_find_by as find_by
    from selenium.webdriver.common.by.By
    
    class GoogleSearchPage(object):
    
        _search_box = find_by(how=By.NAME, using='q', cacheable=True)
    
        _search_button = find_by(name='btnK')
    
        def __init__(self, driver):
            self._driver = driver
    
        def search(self, keywords):
            self._search_box().click()
            self._search_box().send_keys(keywords)
            self._search_button().click()
    

    Your feedback is appreciated. For more details, please visit https://jeremykao.wordpress.com/2015/06/10/pagefactory-pattern-in-python/

提交回复
热议问题