Open In App
Related Articles

Page Object Model (POM)

Improve Article
Save Article
Like Article

What is POM?
POM is a design pattern which is commonly used in Selenium for Automating the Test Cases. This design pattern can be used with any kind of framework like keyword-driven, Data-driven, hybrid framework, etc.
The Page object is an object-oriented class which acts as an interface for the page of your Application under test. Page class contains web elements and methods to interact with web elements. While Automating the test cases, we create the object of these Page Classes and interact with web elements by calling the methods of these classes.

Page Object Model Design Pattern

Uses of Page Object Model (POM):
This Design Pattern is used in Selenium where web pages are represented by a corresponding class and web elements are represented by the variables of the class and all interactions are possible through the methods or say functions of the class.

Advantages of POM model:

  • Reusability: We can reuse the page class if required in different test cases which means we don’t need to write code for identifying the web elements and methods to interact with them for every test case.
  • Maintainability: As we can see from the above picture test case and page class are different from each other which means we can easily update the code if any new web element is added or existing one updated.
  • Readability: As we can see in the above picture page code is separated form test code which helps to improve code readability.

Implementation of Page Object Model:
Here I’m taking the example of Gmail application to show the implementation of POM.
The Project Hierarchy of my Maven Project is shown below:

Project Hierarchy

TestBase Class:
In this class we create the object of WebDriver class, maximize the browser, launching Url etc.

package test_cases;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
public class TestBase {
    public static WebDriver driver = null;
    public void initialize() throws IOException {
        System.getProperty("user.dir") + 
        driver = new ChromeDriver();
        // To maximize browser
        // Implicit wait
             10, TimeUnit.SECONDS);
        // To open Gmail site
    // Test cleanup
    public void TeardownTest() {

GmailLoginPage Class:
In this class, we identify the web elements of Gmail Login Page and methods to interact with these web elements.

package pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class GmailLoginPage {
    WebDriver driver;
    public GmailLoginPage(WebDriver driver) {
        this.driver = driver;
    // Using FindBy for locating elements
    @FindBy(how = How.XPATH, using = 
            "// input[@type='email']]")
    WebElement emailTextBox;
    @FindBy(how = How.XPATH, using = 
            "// input[@type='password']")
    WebElement passwordTextBox;
    @FindBy(how = How.XPATH, using =
            "// div[@role = 'button' and @id  =
    WebElement nextButton;
    // Defining all the user actions (Methods)
    //that can be performed in the Facebook home page
    // This method is to set Email in the email text box
    public void setEmail(String strEmail) {
        // This method is to set Password in the password text box
    public void setPassword(String strPassword) {
        // This method is to click on Next Button
    public void clickOnNextButton() {;

Similarly, we write the code for Gmail Home Page.

In this class we test the login page of Gmail.

package test_cases;
import org.testng.annotations.Test;
import pages.GmailHomePage;
import pages.GmailLoginPage;
public class GmailLoginTest extends TestBase {
    public void init() throws Exception {
        // driver.get("https://");
        GmailLoginPage loginpage = 

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 16 Jul, 2019
Like Article
Save Article
Similar Reads
Complete Tutorials