PageFactory in selenium

PageFactory is an extended support to POM (PageObjectModel), used to locate webelement in adifferent manner than mentioned here.

Before we learned to declare and locate an WebElement as below :

Using PageFactory


or this can even read as,

The above 2 lines are not sufficient to locate, we need to instantiate the class object through PageFactory, so this is as follows

“this”, as we want to instantiate the webelement is the same class.

If the pagefactory elements are in different class or java file, let’s see how we can access – page object class that holds all the weblements and methods related to login page – this is the test case which actually instantiate LoginPage class object and weblements

some more PageFactory insights

Supported locators

@FindBy(“locatorName”, “value”)
locator name could be any one of the following:


Every time we use (use only, not declaring multiple times) the WebElement, it searches if element present or not,
but if we are sure element is present on current page, then use @CacheLookup to avoid checking the presence and save some time… code as follows


This will return list of webElements matching all the conditions [AND operator]


This will return list of webElements matching any of the [at least one] condition [OR operator]

Reference :

Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our, Thanks!

1 Response

  1. June 7, 2016

    […] PageFactory post for more […]

Leave a Reply

Your email address will not be published. Required fields are marked *