- What is BluePrism? Know about the benefits of BluePrism Certification
- What is Silk test Workbench? : Comprehensive Guide
- RPA Developer Salary
- What is Selenium and Why Should You Learn Selenium | Everything You Need to Know
- Robotic Process Automation with Blue Prism | A Definitive Guide with Best Practices [ OverView ]
- An Overview of Patch Workflows | Benefits and Special Features [ For Freshers and Experience ]
- Selenium Commands : Selenese | Everything You Need to Know [ OverView ]
- Robotic Process Automation Developer Salary [ For Freshers and Experience ]
- List of Basic Powershell Commands | Every Developer Should Know [ OverView ]
- Tosca vs Selenium | Differences and Which Should You Learn?
- Chef vs Puppet: Major Differences and Similarities
- what is TestNG Annotations in Selenium Webdriver?
- Blue Prism Certification Guide
- RPA Tools Comparison
- Ansible vs Chef
- How to Download & Install Selenium Ide?
- RPA vs Selenium
- RPA Blue Prism Certification Guide
- Robotic Process Automation Career Scope
- How to Take A Screenshot in Selenium WebDriver?
- Robot Class in Selenium Webdriver
- CSS Selectors in Selenium
- Vector Class in Java
- Page Object Model in Selenium With Page Factory
- How to Handle Alert and Pop-ups in Selenium WebDriver?
- Selenium Webdriver
- What is Selenium?
- How to Handle Actions Class in Selenium WebDriver?
- Waits in Selenium WebDriver
- Select Class in Selenium WebDriver
- What is BluePrism? Know about the benefits of BluePrism Certification
- What is Silk test Workbench? : Comprehensive Guide
- RPA Developer Salary
- What is Selenium and Why Should You Learn Selenium | Everything You Need to Know
- Robotic Process Automation with Blue Prism | A Definitive Guide with Best Practices [ OverView ]
- An Overview of Patch Workflows | Benefits and Special Features [ For Freshers and Experience ]
- Selenium Commands : Selenese | Everything You Need to Know [ OverView ]
- Robotic Process Automation Developer Salary [ For Freshers and Experience ]
- List of Basic Powershell Commands | Every Developer Should Know [ OverView ]
- Tosca vs Selenium | Differences and Which Should You Learn?
- Chef vs Puppet: Major Differences and Similarities
- what is TestNG Annotations in Selenium Webdriver?
- Blue Prism Certification Guide
- RPA Tools Comparison
- Ansible vs Chef
- How to Download & Install Selenium Ide?
- RPA vs Selenium
- RPA Blue Prism Certification Guide
- Robotic Process Automation Career Scope
- How to Take A Screenshot in Selenium WebDriver?
- Robot Class in Selenium Webdriver
- CSS Selectors in Selenium
- Vector Class in Java
- Page Object Model in Selenium With Page Factory
- How to Handle Alert and Pop-ups in Selenium WebDriver?
- Selenium Webdriver
- What is Selenium?
- How to Handle Actions Class in Selenium WebDriver?
- Waits in Selenium WebDriver
- Select Class in Selenium WebDriver

Page Object Model in Selenium With Page Factory
Last updated on 21st Sep 2020, Artciles, Automation, Blog
- Page Object Model, also known as POM is a design pattern in Selenium that creates an object repository for storing all web elements. It is useful in reducing code duplication and improves test case maintenance.
- In Page Object Model, consider each web page of an application as a class file. Each class file will contain only corresponding web page elements. Using these elements, testers can perform operations on the website under test.
Page Factory in Selenium
- Page factory is the way to implement page object models. It is an inbuilt concept for the Page object model but very optimized.
- One of the biggest benefits of Page Factory is AjaxElementLocatorFactory Class. It works on lazy loading concept, i.e. a timeout for web elements is assigned to the page object class with the help of AjaxElementLocatorFactory. Hence, when an operation is performed on an element, the wait for its visibility starts from that particular moment only. If the element is not found in the given time frame, then the test case execution will throw an exception.
Subscribe For Free Demo
Error: Contact form not found.
Creating a page object model with page factory in Selenium WebDriver
Here, we will consider one Gmail application to learn the implementation of the page object model with a page factory in Selenium WebDriver.
Let us look at the steps to be followed for implementing the page object model using the page factory concept.
Step 1:Create a test base class. Here, we implement waits, create an object of WebDriver, maximize bowser, launch URL, etc. in this example, we will focus on chrome browser and set the system property to launch the Chrome browser.
The programming code for the testbase.java class is given below.

Step 2 :Now create classes for Facebook Login Page, Facebook Home page to hold web elements and locators. Usually, we should create page objects for all pages in AUT.
For every page, we create a separate class with a constructor. Now, you should identify locators and store them in one class. It increases the reusability of locators for multiple methods whenever necessary. For any code changes in the UI, it makes the code maintenance easy and making changes to a particular page is simple. Here you should create Java files for both pages after the test base class to hold locators and their elements.
Step 3: As per the scenario, the script should work as follows:
- Launch the Chrome browser and open Facebook.com
- Enter the valid credentials and login to the Facebook home page.
- Verify the credentials and log out.
In the end, you need to create one testing.xml file. The page object model always helps you to develop faster with cleaner code tests.
Advantages of Page Object Model
- Helps with easy maintenance: POM is useful when there is a change in a UI element or there is a change in an action. An example would be if a drop down menu is changed to a radio button.
In this case, POM helps to identify the page or screen to be modified. As every screen will have different java files, this identification is necessary to make the required changes in the right files. This makes test cases easy to maintain and reduces errors.
- Helps with reusing code: As already discussed, all screens are independent. By using POM, one can use the test code for any one screen, and reuse it in another test case. There is no need to rewrite code, thus saving time and effort.
- Readability and Reliability of scripts: When all screens have independent java files, one can easily identify actions that will be performed on a particular screen by navigating through the java file. If a change must be made to a certain section of code, it can be efficiently done without affecting other files.
Difference Between Page Object Model and Page Factory in Selenium
Page Object Model | Page Factory |
Finding web elements using By | Finding web elements using @FindBy |
POM does not provide lazy initialization | Page Factory does provide lazy initialization |
Page Object Model is a design pattern | PageFactory is a class which provides implementation of Page Object Model design pattern |
In POM, one needs to initialize every page object individually | In PageFactory, all page objects are initialized by using the initElements() method |
Run the code in order to test the workings of Page Object Model and Page Factory. Since these are important Selenium functions, testers need to be able to use them with ease and accuracy for Selenium automation. This will help them streamline automation testing efforts and yield results quicker.