• What is Automation Testing - Advantages & Types of Tools
  • What is Selenium IDE, Selenium RC, Selenium WebDriver, Selenium Grid?
  • Selenium IDE, Firebug & Firepath Installation


  • Selenium WebDriver Architecture
  • Selenium Installation
  • Challenges and Limitations of Selenium
  • First Selenium WebDriver Script
  • Working with Firefox Browser
  • Solution - Failed To Launch Browser Using Selenium WebDriver
  • Working with Chrome Browser
  • Working with IE Browser
  • Difference Between FindElement & FindElements
  • Install Firebug, Fire path and other add on for Selenium
  • Locators in Selenium
  • Dynamic Xpath
  • Dynamic CSS
  • Handle drop-downs
  • How to work with file upload
  • Handle Alerts & Popups
  • Handle Multiple Windows
  • Mouse Hover event in Selenium
  • Right Click
  • Double Click
  • Drag and Drop
  • Capture Screenshots in Selenium
  • Parameterization
  • Synchronization
  • Implicit Wait, Explicit Wait and Fluent Wait in Selenium
  • Implicit Waits
  • Explicit WebDriver Waits
  • Fluent Wait In Selenium
  • Apache POI
  • How To Read Data From Excel File
  • How To Write Data In Excel File
  • Database Testing Using MSSQL
  • Database Testing Using MySQL
  • Database Testing Using DB2
  • Handle Ajax Call in Selenium
  • Listeners in Selenium
  • Handling JavaScript in Selenium
  • Stale Element Reference Exception in Selenium
  • Integrate Sikuli with Selenium
  • Headless Browser Testing 
  • Headless Browser Testing using HtmlUnitDriver
  • Headless Browser Testing using PhanthomJSDriver


  • TestNG Installation
  • TestNG Complete Tutorial


  • Extent Reports Introduction
  • Extent Reports Generation
  • Capturing Screenshots & Including In Extent Reports
  • Extent Reports Version 4


  • ANT Build Tool - How To Download & Install
  • Maven Build Tool - How To Download & Install
  • Creating Maven Selenium Project
  • GIT Integration with Selenium
  • Jenkins - How To Download & Install
  • Jenkins - Executing TestNG Scripts
  • Jenkins - Generating Reports After Test Execution
  • Jenkins - Executing Maven Project
  • Create build and Execute build for nightly execution
  • Send Email report based on build Status
  • Selenium Continuous Integration with Jenkins [Selenium – Maven – Git – Jenkins] – Step By Step Guide


  • Running Selenium Tests On BrowserStack
  • Kobiton - Mobile Testing Platform with Real Devices


  • Mobile Testing Platform with Real Devices


  • What is Framework & Types of Framework
  • Page Object Model Design Pattern
  • Data Driven Framework
  • How to explain Test Automation Framework or Selenium Automation Framework Architecture In Interview

  • API Testing:

  • Learn API Testing
  • Postman Tutorial (API Testing with Postman)


  • Test Automation Framework Interview Questions
  • Selenium Interview Questions
  • TestNG Interview Questions
  • Java Interview Questions
  • Python Interview Questions
  • API Testing Interview Questions


  • Automation Tester Resume
  • Page Object Model with Page Factory in Selenium – Complete Guide

    Page Object Model with Page Factory in Selenium

    In this tutorial, we will learn about Page Object Model design pattern. We will see complete details of Page Object Model Design Pattern with Page Factory in Selenium with practical examples.

    1. What is POM Design Pattern (Page Objects Model)
    2. What is Page Factory
    3. What is the difference between POM and Page Factory
    4. Advantages of Page Objects Model Framework
    5. Creating a POM with Page Factory in Selenium WebDriver

    What is Page Object Model Design Patten (POM):

    Page Object Model is a Design Pattern which has become popular in Selenium Test Automation. It is widely used design pattern in Selenium for enhancing test maintenance and reducing code duplication. Page object model (POM) can be used in any kind of framework such as modular, data-driven, keyword driven, hybrid framework etc.  A page object is an object-oriented class that serves as an interface to a page of your Application Under Test(AUT). The tests then use the methods of this page object class whenever they need to interact with the User Interface (UI) of that page. The benefit is that if the UI changes for the page, the tests themselves don’t need to change, only the code within the page object needs to change. Subsequently, all changes to support that new UI is located in one place.

    What is Page Factory:

    We have seen that ‘Page Object Model’ is a way of representing an application in a test framework. For every ‘page’ in the application, we create a Page Object to reference the ‘page’ whereas a ‘Page Factory’ is one way of implementing the ‘Page Object Model’.

    What is the difference between Page Object Model (POM) and Page Factory:

    Page Object is a class that represents a web page and hold the functionality and members.
    Page Factory is a way to initialize the web elements you want to interact with within the page object when you create an instance of it.

    Advantages of Page Object Model Framework:

    • Code reusability – We could achieve code reusability by writing the code once and use it in different tests.
    • Code maintainability – There is a clean separation between test code and page specific code such as locators and layout which becomes very easy to maintain code. Code changes only on Page Object Classes when a UI change occurs. It enhances test maintenance and reduces code duplication.
    • Object Repository – Each page will be defined as a java class. All the fields in the page will be defined in an interface as members. The class will then implement the interface.
    • Readability – Improves readability due to clean separation between test code and page specific code

    Creating a Page Object Model with Page Factory in Selenium WebDriver:

    Here I will take Gmail Application to showcase implementation of Page Object Model Design Pattern with Page Factory using Selenium with Java.

    Scenario: Enter valid credentials in the ‘Facebook Login’ Page and redirects to the ‘Facebook Home‘ Page.

    Must Read: Complete Selenium WebDriver Tutorial

    The structure of my project (Maven Project) is as follows:

    Follow below steps to Implement Page Object Model Design Pattern.

    Step 1: Creating TestBase class. Here we create an object of WebDriver, maximize browser, implementing waits, launching URL and etc.,

    In the below example program, I have taken chrome browser and set the System Property to launch chrome browser. (BASE CLASS)

    Must Read: How To Test TestNG Tests Using Jenkins

    Step 2: Creating classes for each page (Eg., Facebook Login Page,  Facebook Inbox Page) to hold element locators and their methods. Usually, we create page objects for all available pages in the AUT. For each page, we create a separate class with a constructor. Identify all the locators and keep them in one class. It allows us to reuse the locators in multiple methods. It allows us to do easy maintenance, if there is any change in the UI, we can simply change on one Page.

    Here, I create java files ( and for the corresponding pages (Facebook Login Page, and Facebook Inbox Page) to hold element locators and their methods. (Webpage 1) (Webpage 2)

    Step 3: Creating Test (Eg., FBLoginTest) based on above pages. As per my test scenario which was mentioned above, scripts run as follows.

    1. Launch browser and open
    2. Enter user credentials and do signin
    3. Verify the loggedIn user name and do logout (Test Case 1)

    Step 4: Creating testng.xml file

    Must Read: Complete TestNG Tutorial

    Below is the testng.xml file.

    The Page Object Model design pattern helps you develop faster, easier and cleaner tests. You can read more on Page Object Model Design Pattern on SeleniumHQ Official Site. Hope you liked reading the article. If you have any queries, do let us know in the comments section below and share it with your friends.

    Must Read: Data Driven Testing Framework In Selenium

    Here I have hand-picked few posts which will help you to learn some interesting stuff:

    Page Object Model Design Pattern

    Get our latest blog posts delivered to your inbox

    Subscribe and get popular blog posts about software testing industry.


    12 thoughts on “Page Object Model with Page Factory in Selenium – Complete Guide”

    1. Hello Rajkumar,

      Seriously, your site is the best I would say for any layman to learn Selenium. I have been browsing through many websites to learn Selenium, but I feel so glad that I stumbled on yours. The concepts are explained so well in a way easy for beginners to learn.

      Thanks a lot!

      • Thanks for your kind words Pia Nelson.

    2. How to define @FindBy for a list in webpage and how to use it in the the test class

    3. Hi,
      Thank you for a very comprehensive tutorial; it is very informative. I have experienced one issue, however: my tests are failing due to NullPointerException. I have replicated your FBLogin example, and, somehow, loginpage.clickOnLoginButton() is throwing an exception.

      Kind regards,

      • Hi Walker,

        Modify the below line of code in your

        @FindBy(how=How.XPATH, using="//input[@type='submit'][@id='u_0_5']") WebElement signinButton;

        with the below code

        @FindBy(how=How.XPATH, using="//*[@id='loginbutton']") WebElement signinButton;


    4. Ya submit button taking dynamic cpath do better take I’d

      By the way the article is super

      • Thanks Padma

    5. Hi Rajkumar,

      Very much helpful & informative site for learning advanced concepts. I do have one query as given below:


      instead of XPATH, can we give ‘How.ID’ or ‘How.Name’? If yes, what will be the following code instead of >> using=”//input[@type=’email’][@name=’email’]”

      Eknath Dhauskar

      • You can use it.
        just take [@name=’email’]

        • Thanks for your reply…

    6. HI Raj,
      Nice job. Your WebPages are really helpful to me,. I just have 2 questions for you regarding this example.

      Do you know if I could use the Chrome Driver from Docker ? When I was running this sample where the driver is from the docker stand-alone chrome driver:
      1. The code was able to identify the Text area of the “username”, and “password”,
      2. But it was not able to find the id of “loginbutton”, and the case was failed there.
      3. And if I replace the code with the routine way, such as:
      >> driver.findElement(“loginbutton”)).click(), This step was able to going through.

      While I was trying to find out which steps fails in the example, I have tried to take a screen shot from the page after “login button” was clicked, But somehow, the png file was in dark, that I can merely read the foreground contents. Do you have any idea what could be wrong.

      Thanks again for all these messages,


      • Hi Jack, I have never tried docker stuff. If any luck, pls try to answer here on how you achieved it. If you want to write a guest post on this, you can send a draft using our contact form. I will review and post it.

    Leave a Comment

    Share via
    Copy link
    Powered by Social Snap