POM and Page Factory in Selenium

Related Product On This Page What is Page Object Model in Selenium?

February 16, 2026 · 14 min read · Tool Comparison
Related Product

POM and Page Factory in Selenium

Ever struggled to hold your stable as theUI keeps changing?

Testers much face this issue and I ’ ve realise team spend around 30–40 % of their mechanization time just updating broken locators and fixing repetitive failures.

Small UI tweaks riffle through the,slowing down releases, delaying feedback, and do feel more like a onus than a productivity boost.

That ’ s where structured design patterns like thePage Object Model (POM) and Page Factory help.

They simplify maintenance, reduce duplication, and create examination far more resilient to UI changes—especially as the application grows.

Overview

POMis a blueprint pattern in Selenium that separates page-specific UI elements and activeness into dedicated category. It helps create clean, readable, and modular automation fabric.

Purpose: The purpose of POM in Selenium is to direct UI elements and actions into dedicate page classes, making tests easier to maintain and protecting them from frequent UI modification.

Implementation

  • Create one class per webpage (LoginPage, HomePage, etc.).
  • Store web elements as variables and user actions as method.
  • Instantiate page family inside test scripts.
  • Keep locators and business logic separate from exam logic.

Page Factoryis an enhanced version of POM that apply annotations to initialise and grapple UI elements more efficiently.

Purpose: The determination of Page Factory is to simplify element initialization in POM using annotations like @ FindBy, reducing boilerplate code and making page classes more readable and efficient.

Implementation

  • Use @ FindBy to delimitate elements in the page family.
  • Initialize elements using PageFactory.initElements (driver, this).
  • Write activity methods that interact with these elements.
  • Call page methods straightaway in examination scripts.

Example:LoginPage.java

import org.openqa.selenium. *; import org.openqa.selenium.support. *; public class LoginPage {@ FindBy (id = `` username '') WebElement exploiter; @ FindBy (id = `` parole '') WebElement pass; @ FindBy (id = `` loginBtn '') WebElement login; public LoginPage (WebDriver driver) {PageFactory.initElements (driver, this);} public void login (String u, String p) {user.sendKeys (u); pass.sendKeys (p); login.click ();}}

This clause explores how to use Page Object Model and Page Factory in Selenium mechanization projects to maintain test case easily.

What is Page Object Model in Selenium?

Page Object Model (POM) is a that creates an object repository to store all web elements of an coating. It reduces code duplicate and simplifies t upkeep by organizing ingredient in separate classes.

In POM, each web page of the coating is typify as a form file. These class file control solely the web elements specific to their corresponding Page, allowing testers to interact with elements and execute actions on the web application efficiently.

According toCrissy Joshua, Page Object Model brings long-term stability to Selenium automation by clearly separating examination logic from page structure, get it easier to update locator and activity as the application acquire without touch the test cases themselves.

Read More:

Advantages of Page Object Model

The Page Object Model offers several benefits that get examination mechanization more effective and maintainable:

  • Easy Maintenance: POM is useful when there is a modification in a UI element or a alteration in action. An illustration would be: a drop-down menu is changed to a wireless button. In this case, POM helps to name the page or screen to be modified. As every blind will hold different Java file, this identification is necessary to make changes in the correct file. This makes tryout cases easy to preserve and reduces erroneousness.
  • : As already discuss, all screens are independent. By using POM, one can use the test code for one screen, and reprocess it in another test example. There is no demand to rewrite codification, thus saving clip and effort.
  • Readability and Reliability of Scripts: When all screens feature autonomous java file, one can quickly identify actions execute on a particular blind by navigate through the java file. If a change must be made to a specific code section, it can be efficiently done without affecting other files.

When combine with real-device and, these advantages get even more impactful.

Running POM-based exam on platforms like ensures they behave consistently across different browser adaptation and operating systems. systems.

With exigent admission to logs, videos, and debugging insights, teams can validate UI flows and maintain their POM framework with higher truth and reliability.

Struggling with unstable POM exam?

Cross-browser inconsistencies retard debugging. Run your Selenium tests on existent browsers for honest results.

Key Concepts in POM

The Page Object Model follows a structured approach that revolves around key components such as Page Classes, Locators, and Methods. Understanding these concepts is crucial for building efficient and maintainable test automation frameworks.

Page Classes

Each web page in the application is represented by a freestanding class file in the Page Object Model. This class acts as a container for the page ’ s web elements and related action. By mastermind pages into distinct grade, POM keeps the tryout codification clean and easy to keep.

Locators in POM

Locators define how to identify web elements on a page. POM uses locators such as ID, name, XPath, CSS selectors, or early strategies to map elements in the page sort. This centralised approach get updating locators easier when the UI alteration.

Methods in POM

Methods are functions within the page assort that perform actions on the page ’ s elements. These methods abstract user interaction such as chatter a push, entering text, or retrieving page data. Test scripts can call these methods to perform action, improving code readability and reusability.

Platforms like further streamline POM-based automation by enabling testers to execute tests on existent browsers and devices without the need for complex local setups.

This allows teams to focus on compose clean, maintainable codification while control cross-browser and cross-device compatibility at scale.

Talk to an Expert

Implementing POM in Selenium Project

As already discussed, each java family will contain a comparable page file. This tutorial will create 2-page file.

  • BrowserStackHomePage
  • BrowserStackSignUpPage

Each of these files will moderate UI elements or Objects which are present on these screen. It will also contain the operations to be do on these constituent.

Also Read:

Sample Project Structure for POM

BrowserStackHomePage Java File

Explanation of Code

  • Code Line-10 to 11:Identifying elements present on BrowserStack Home Page such asheader and Get Started button
  • Code Line-17 to 24:Performing action on identified objects on BrowserStack Home Page

Code Snippet

package browserStackPages; import static org.testng.Assert.assertEquals; import org.openqa.selenium.By; meaning org.openqa.selenium.WebDriver; public course BrowserStackHomePage {WebDriver driver; By Header=By.xpath (`` //h1 ''); By getStarted=By.xpath (`` // * [@ id='signupModalButton '] ''); public BrowserStackHomePage (WebDriver driver) {this.driver=driver;} public null veryHeader () {String getheadertext=driver.findElement (Header) .getText (); assertEquals (`` App & amp; Browser Testing Made Easy '', getheadertext);} public void clickOnGetStarted () {driver.findElement (getStarted) .click ();}}

BrowserStackSignUpPage Java File

Explanation of Code

  • Code Line-10 to 14:Identifying element present on such asheader and Get Started button
  • Code Line-20 to 35:Performing actions on identified objects on the BrowserStack SignUp Page

Code Snippet

package browserStackPages; meaning static org.testng.Assert.assertEquals; import org.openqa.selenium.By; meaning org.openqa.selenium.WebDriver; public class BrowserStackSignUpPage {WebDriver driver; By Header = By.xpath (`` //h1 ''); By userName = By.xpath (`` // * [@ id='user_full_name '] ''); By businessEmail = By.xpath (`` // * [@ id='user_email_login '] ''); By password = By.xpath (`` // * [@ id='user_password '] ''); public BrowserStackSignUpPage (WebDriver driver) {this.driver = driver;} public null veryHeader () {String getheadertext = driver.findElement (Header) .getText () .trim (); assertEquals (`` Create a Gratis Account '', getheadertext);} public void enterFullName (String arg1) {driver.findElement (userName) .sendKeys (arg1);} public void enterBusinessEmail (String arg1) {driver.findElement (businessEmail) .sendKeys (arg1);} public nullity enterPasswrod (String arg1) {driver.findElement (parole) .sendKeys (arg1);}}

BrowserStackSetup Java File

Explanation of Code

  • Code Line-21 to 27:Setting up browser and website to accomplish tryout handwriting
  • Code Line-29 to 43:Initializing driver objective toBrowserStackHomePage & BrowserStackSignUpPageand do actions on those pages

Code Snippet

package browserStackSetup; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import browserStackPages.BrowserStackHomePage; import browserStackPages.BrowserStackSignUpPage; public grade BrowserStackSetup {String driverPath = `` C: \\geckodriver.exe ''; WebDriver driver; BrowserStackHomePage objBrowserStackHomePage; BrowserStackSignUpPage objBrowserStackSignUpPage; @ BeforeTest public void setup () {System.setProperty (`` webdriver.chrome.driver '', `` C: \\BrowserStack\\chromedriver.exe ''); driver = new ChromeDriver (); driver.manage () .timeouts () .implicitlyWait (10, TimeUnit.SECONDS); driver.get (`` https: //www.browserstack.com/ '');} @ Test (priority = 1) public void navigate_to_homepage_click_on_getstarted () {objBrowserStackHomePage = new BrowserStackHomePage (driver); objBrowserStackHomePage.veryHeader (); objBrowserStackHomePage.clickOnGetStarted ();} @ Test (priority = 2) public void enter_userDetails () {objBrowserStackSignUpPage = new BrowserStackSignUpPage (driver); objBrowserStackSignUpPage.veryHeader (); objBrowserStackSignUpPage.enterFullName (`` TestUser ''); objBrowserStackSignUpPage.enterBusinessEmail (`` TestUser @ gmail.com ''); objBrowserStackSignUpPage.enterPasswrod (`` TestUserPassword '');}}

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

What is Page Factory in Selenium?

Page Factory is a grade render by to support Page Object Design model. In Page Factory, examiner use@FindByannotation. TheinitElementsmethod is used to initialize web elements.

1. @ FindBy: An annotation used in Page Factory to situate and announce web constituent using different locator. Below is an instance of declaring an element use@FindBy

@ FindBy (id= '' elementId '') WebElement element;

Similarly, one can use@FindBywith different location strategies to notice web elements and do actions on them. Below are that can be used:

  • ClassName
  • CSS
  • Name
  • TagName
  • PartialLinkText

2. initElements (): initElementsis a inactive method in Page Factory course. Using theinitElementsmethod, one can initialize all the web ingredient site by@FindByannotation.

3. slothful initialization: AjaxElementLocatorFactoryis a indolent load concept in Page Factory. This lonesome identifies web elements when used in any operation or activity. The timeout of a web constituent can be assigned to the object grade with the helper of theAjaxElementLocatorFactory.

Must-Read:

Implementing Page Factory in Selenium Project

This will try to use the same projection expend for the POM Model. It will reuse the 2-page files and implement Page Factory.

  • BrowserStackHomePage
  • BrowserStackSignUpPage

As discussed originally, each of these files will only contain UI elements or Objects present on these blind along with the operations to be do on these elements.

Struggling with unstable POM tests?

Cross-browser inconsistency slows debugging. Run your Selenium test on real browsers for dependable results.

Sample Project Structure for Page Factory

The labor construction will not change as the like labor is being used. As already mentioned, Page Factory supports Page Object Model design pattern.

BrowserStackHomePage Java File

Explanation of Code

  • Code Line-13 to 17:Identifying component present on BrowserStack Home Page such asheader and Get Startedpush using Page Factory@FindByannotation
  • Code Line-23 to 30:Performing actions on identified objects on the BrowserStack Home Page

Code Snippet

bundle browserStackPages; import static org.testng.Assert.assertEquals; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; public class BrowserStackHomePage {WebDriver driver; @ FindBy (xpath = `` //h1 '') WebElement Header; @ FindBy (xpath = `` // * [@ id='signupModalButton '] '') WebElement getStarted; public BrowserStackHomePage (WebDriver driver) {this.driver = driver; PageFactory.initElements (driver, this);} public void veryHeader () {String getheadertext = Header.getText (); assertEquals (`` App & amp; Browser Testing Made Easy '', getheadertext);} public vacancy clickOnGetStarted () {getStarted.click ();}}

BrowserStackSignUpPage Java File

Explanation of Code

  • Code Line-14 to 24:Identifying element on, such as theheader andGet Startedpush, using Page Factory@FindByannotation.
  • Code Line-26 to 46:Performing actions on identified object on the BrowserStack SignUp Page

Code Snippet

packet browserStackPages; import static org.testng.Assert.assertEquals; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; public class BrowserStackSignUpPage {WebDriver driver; @ FindBy (xpath = `` //h1 '') WebElement Header; @ FindBy (xpath = `` // * [@ id='user_full_name '] '') WebElement userName; @ FindBy (xpath = `` // * [@ id='user_email_login '] '') WebElement businessEmail; @ FindBy (xpath = `` // * [@ id='user_password '] '') WebElement parole; public BrowserStackSignUpPage (WebDriver driver) {this.driver = driver; PageFactory.initElements (driver, this);} public void veryHeader () {String getheadertext = Header.getText () .trim (); assertEquals (`` Create a FREE Account '', getheadertext);} public void enterFullName (String arg1) {userName.sendKeys (arg1);} public null enterBusinessEmail (String arg1) {businessEmail.sendKeys (arg1);} public void enterPasswrod (String arg1) {password.sendKeys (arg1);}}

BrowserStackSetup Java File

Explanation of Code

  • Code Line-21 to 27:Setting up of browser and website to execute our scripts
  • Code Line-29 to 43:Initializing driver object to BrowserStackHomePage & amp; BrowserStackSignUpPage and performing actions on those pages.

Code Snippet

package browserStackSetup; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.BeforeTest; importee org.testng.annotations.Test; import browserStackPages.BrowserStackHomePage; signification browserStackPages.BrowserStackSignUpPage; public course BrowserStackSetup {String driverPath = `` C: \\geckodriver.exe ''; WebDriver driver; BrowserStackHomePage objBrowserStackHomePage; BrowserStackSignUpPage objBrowserStackSignUpPage; @ BeforeTest public vacuum frame-up () {System.setProperty (`` webdriver.chrome.driver '', `` C: \\BrowserStack\\chromedriver.exe ''); driver = new ChromeDriver (); driver.manage () .timeouts () .implicitlyWait (10, TimeUnit.SECONDS); driver.get (`` https: //www.browserstack.com/ '');} @ Test (priority = 1) public nullity navigate_to_homepage_click_on_getstarted () {objBrowserStackHomePage = new BrowserStackHomePage (driver); objBrowserStackHomePage.veryHeader (); objBrowserStackHomePage.clickOnGetStarted ();} @ Test (priority = 2) public nullity enter_userDetails () {objBrowserStackSignUpPage = new BrowserStackSignUpPage (driver); objBrowserStackSignUpPage.veryHeader (); objBrowserStackSignUpPage.enterFullName (`` TestUser ''); objBrowserStackSignUpPage.enterBusinessEmail (`` TestUser @ gmail.com ''); objBrowserStackSignUpPage.enterPasswrod (`` TestUserPassword '');}}

Test Result

Difference between Page Object Model & amp; Page Factory in Selenium

Page Object ModelPage Factory
Finding web elements usingByFinding web elements utilise@FindBy
POM does not furnish slothful initialisationPage Factory does provide lazy initialization
Page Object Model is a pattern patternPageFactory is a class that implement the Page Object Model blueprint pattern.
In POM, one needs to initialize every page object individuallyIn PageFactory, all page object are initialized by using theinitElements () method

Run the code to test the workings of the Page Object Model (POM) and Page Factory. Since these are important Selenium functions, quizzer need to be able to use them with relief and truth for. This will assist them streamline efforts and get results quicker.

Optimize Your POM and Page Factory Framework with BrowserStack Automate

Using POM and Page Factory assist mastermind your Selenium model, but ensuring that these tests run reliably across requires consistent cross-browser execution.

BrowserStack Automate enables you to run your POM-based tests on a cloud of real background and mobile browsers, validating that your locators and workflows bear as expected across versions and operating systems.

Key Advantages of using BrowserStack Automate include:

  • Real Browser Coverage:Execute tests on existent Chrome, Firefox, Safari, and Edge versions, ensuring your Page Objects work in the same environments your users trust on.
  • Reliable Debugging Tools:Access videos, screenshots, browser logarithm, console logs, and network logs to quickly name locator mismatch, timing subject, and browser-specific incompatibility.
  • Faster Maintenance:Easily detect failing component or outdated selectors using visual evidence and browser data, helping team update Page Objects with better accuracy.
  • Parallel Execution at Scale:Run multiple POM-based tests simultaneously, reducing overall execution time and accelerating feedback cycles.
  • Seamless CI Integration:Integrate your POM/Page Factory framework with, GitHub Actions, CircleCI, Azure DevOps, and more to automate cross-browser testing in your pipeline.

By combining structured page models with BrowserStack ’ s real-browser infrastructure, teams achieve more stable mechanization, faster triaging, and greater sureness in their end-to-end workflow.

Other Design Patterns used in Selenium

Early Design Patterns employ in Selenium

are pivotal. There are different other design patterns that are utilise in Selenium such as:

  1. Singleton Design Pattern
  2. Fluent Page Object Model
  3. Factory Design Pattern
  4. Facade Design Pattern

Singleton Design Pattern: The Singleton designing pattern ensure that no more than one case of a class is create. It is often expend when a single instance of an aim is required to organize actions across the scheme. For exemplar, in Selenium, the WebDriver object is typically a Singleton, as there should be only one case of the browser for the entire test run.

Fluent Page Object Model: The Fluent Page Object Model is an propagation of the Page Object Model, where method are chain together to constitute a silver-tongued interface. This makes the test codification more readable and concise, as multiple actions can be perform on the page in a single line of code.

Factory Design Pattern: This is used to create representative of classes. It is often used when a single class is not enough to create the needful objects, and multiple subclasses are required. This pattern provides a way to encapsulate the object creation operation and makes it leisurely to change the object creation process without impact the rest of the code.

Facade Design Pattern: The Facade design pattern provides a simplified interface to a complex system. It is used to make it easier to use the system by enshroud its complexity behind a single interface. The Facade form can be used in Selenium to provide a simplified API for interacting with the browser, making it easier to pen tests that are maintainable and leisurely to read.

Read More:

Conclusion

Page Object Model (POM) and Page Factory are essential practice for building scalable, maintainable, and efficient test mechanization frameworks in Selenium. By organizing web element and actions into devote page classes and leveraging annotations for element initialization, these patterns simplify test codification management and reduce duplication.

Incorporating platforms like BrowserStack into your farther heighten the effectiveness of POM and Page Factory by enabling seamless and on real environments. Together, these attack ensure more reliable test automation and faster liberation rhythm for modern web applications.

Useful Resources for Automation Testing in Selenium

Methods, Classes, and Commands

Configuration

XPath

Locators and Selectors

Waits in Selenium

Frameworks in Selenium

Miscellaneous

Best Practices, Tips and Tricks

Design Patterns in Selenium: Page Object Model and Page Factory

Action Class

TestNG and Selenium

JUnit and Selenium

Use Cases

Types of Testing with Selenium

Tags

FAQs

POM is a blueprint pattern that part page component and activity into consecrate family. Page Factory is an propagation of POM that expend @ FindBy annotations and lazy element initialisation to trim boilerplate codification. In short, POM defines the structure; Page Factory simplifies element initialization.

POM improves maintainability, readability, and reusability. When UI changes occur, you only update locators in one place—the Page Object—while trial handwriting remain unswayed. This reduces flakiness and makes mechanization easy to scale.

You technically can, but it ’ s not recommended. Page Factory act best inside a POM construction where each page has its own class. This keeps your framework orchestrate and ensures elements and actions are flawlessly distinguish from test logic.

57,000+ Views

# Ask-and-Contributeabout this matter with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free