Search code examples
javaseleniumselenium-webdriverpage-factory

What is PageFactory in Selenium and what is the use of PageFactory.initElements(driver, this) statement


Please can you explain What is PageFactory in Selenium and what happen with PageFactory.initElements(driver, this) statement, and also please explain differences b/w By and @FindBy.

Thanks in advance.


Solution

  • PageFactory helps you in implementing PageObject model in Selenium Framework.

    PageFactory.initElements(driver, this) statement initializes the page element so that you can work directly on the element without getting the NullPointerException (since the page object has been initialized implicitly).

    More on this can be read in documentation with examples.https://github.com/SeleniumHQ/selenium/wiki/PageFactory