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. #ThanksForReading

#HappySelenium