Difference Between Page Object Model And PageFactory In Selenium WebDriver

Hello Folks,

In this post, we will see what is difference between Page Object Model and Page Factory in Selenium WebDriver. This is also a very frequently asked interview question.

Before we proceed. first go through to below posts:

Introduction of Page Object Model

Plain Page Object Model

Page Factory

After reading above posts, you must have got differences between Page Factory and Page Object model. We will summarize all points here.

  1. A Page Object Model is a test design pattern which says organize page objects as per pages in such a way that scripts and page objects can be differentiated easily. A Page Factory is one way of implementing PageObject Model which is inbuilt in selenium.
  2. In plain POM, you define locators using ‘By’ while in Page Factory, you use FindBy annotation to define page objects.
  3. Page Object Model is a design approach while PageFactory is a class which provides implementation of Page Object Model design approach.
  4. Plain POM is not optimal as it does not provide lazy initialization while Page Factory provides lazy initialization.
  5. Plain POM will not help in StaleElementReferecneException while Page Factory takes care of this exception by relocating web element every time whenever it is used.
  6. In plain page object model, you need to initialize every page object individually otherwise you will encounter NullPointerException while In PageFactory all page objects are initialized (Lazily) by using initElements() method.

Hope, now you can answer this question well in interview. If you find any other difference, kindly comment. I will include that in post.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

3 thoughts on “Difference Between Page Object Model And PageFactory In Selenium WebDriver

  1. Hi, Your article is very interesting. I will share my thoughts here.

    In POM (Page Object Model) you create new class for every new page/URL and put all your element identification methods in it.


    If you navigate to my Github – OrangeHRM automation sample project, you will notice that I have two .java files there. Dashboard and Login. So whatever element I identify on Login page, I put in Login.java and whatever elements I identify on Dashboard, I put it in Dashboard.java. This is really helpful in terms of maintenance and usability. So, if I want to work with any element present on Dashboard, I just have to say Dashboard.element. If case of change of element, I just have to change it at one place.

    Page Factory is annotation inside selenium which you give it to class. So, when you define any class as page factory, all your elements inside the class will get loaded while any of element in the class is called. This is really a bad practice if you have 100s elements inside a class and you just have to make use of only one.

    So, I would suggest you to go with POM. I do not have C# example, but I have similar one in Java which I have already shared.

    Read more: https://softwaretestingboard.com/q2a/1855/

Leave a Reply

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