Python library provides page factory approach to implement page object model in selenium
- A Page Factory is one way of implementing a Page Object Model. In order to support the Page Object pattern.
- As in Java we are using @findBy, here we are declaring all web element in dictionary. Dictionary keys become WebElement / class member variable with having all extended WebElement methods.
- Initialise all the webElements declared in Point at a time.
- All WebElements methods are re-define to add extra features eg- click method extended to have explicit wait for element to be clickable.
- Cent percent unittest coverage.
pip install selenium-page-factory
Every Page in Page Object Model should have WebDriver object as class member as shown below
class PageClass(PageFactory): def __init__(self,driver): self.driver = driver # Required self.timeout = 15 #(Optional - Customise your explicit wait for every webElement) self.highlight = True #(Optional - To highlight every webElement in PageClass)
Extended WebElements Methods
Note: Every WebElement will be created after verifying it's Presence and visibility on Page at Run-Time.