I've created a framework in C# using the Page Object Model for fun and am now creating a framework in Java to learn Jenkins etc... also for fun.

I have come across the PageFactory concept for Java and have learned it is an optimised version of the POM model. Can anyone tell me how it is optimised?

The way I see it is that while you can store objects on the page with the PageFactory way of doing things. You can also do this with the POM.. with C#, it is even rather simpler using the getter syntax.. but with Java you have to use @FindBy statements.

I might be wrong but it seems you have to write more lines with Java to store elements in your classes then you need to do with C#.

1 Answer 1


Page Object and Selenium's PageFactory are distinct things in nature, usually the latter complement the former.

Page Object is a design pattern aimed at solving the problem of separating the application interface from the HTML interface.

enter image description here

Why do we separate these interfaces? Because web pages elements and functions, as saw by the user, differ from the HTML tree. A user sees albums, artists, and songs; HTML tree have lists, paragraphs, links.

Coupling tests for the HTML tree is usually not the goal - the goal is to create tests for the functions and elements of the page: THe Application API. But in order to programmatically exercise the Application API, one needs to interact with the HTML tree. And Page Objects serve to encapsulate the command transformation from one API to the other.

More info on Martin Fowler's post on PageObject.

Selenium's PageFactory, as mentioned by wec, is simply an annotation that serves to delegate to Selenium the instantiation of some WebElement objects you might want to have on an object that represents a web page or a component.

As mentioned on the Selenium documentation:

There is a PageFactory in the support package that provides support for this pattern, and helps to remove some boiler-plate code from your Page Objects at the same time.

PageFactory serves to make things more succinct, it does not implement the Page Object design pattern out-of-the-box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.