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.

Let’s say we have the webelement [txt_GoogleSrch] on (pageobject page)
and we are trying to access this in [testcase or test script]

With this searchText object, we can access all the variables and methods defined in GoogleHomePage class.

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

rest are same as mentioned…

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 *

%d bloggers like this: