Page Object Model Guide
The complete guide to Selenium POM — what it is, without-vs-with-POM comparison, project layers, base page, login example, PageFactory, design rules and pitfalls.
9 programs
Choose the best training program according to your career.
Improve the performance of your business with our innovative Industrial Training Program.
Read More →
Our instructor-led training classes are designed to make you an expert.
Read More →
Real-life case studies are a great way to demonstrate your practical knowledge.
Read More →
Explore blogs, latest technologies and industry updates with practical examples.
Read More →Browse all available training programs and choose the right one for your career.
Read More →Know more about who we are and what we stand for.
Discover our mission to equip individuals with essential IT skills and industry expertise.
Read More →Learn, practice and plan your career — bilkul free.
Book a free video counselling session and pick the right course for you.
Read More →Download the Selenium Page Object Model guide PDF from Uncodemy: structure, base page, locators and a worked Java login example.
This page offers Uncodemy's Selenium Page Object Model guide as a PDF download. The Page Object Model is a design pattern in which each page or component of the application is represented by a class that holds its locators and actions. The guide shows the structure, a worked Java example and the benefits and pitfalls.
Three quick-access entry points into the same Selenium POM guide PDF: the full guide, the base page + login example pack, and the design rules + locator strategy reference. All PDFs on this page are free to download. No form is required.
The complete guide to Selenium POM — what it is, without-vs-with-POM comparison, project layers, base page, login example, PageFactory, design rules and pitfalls.
A worked Java example using Selenium 4: a shared BasePage with explicit-wait helper, a LoginPage object, and a test that verifies a successful login returns the next page object.
Design rules for good page objects, the locator-strategy stability comparison table, common component objects, common mistakes, and a step-by-step refactoring guide.
All three download buttons open the same Selenium POM guide PDF file. By downloading, you agree to our Privacy Policy. These PDFs are study material only — not a certificate or job guarantee.
The Page Object Model, or POM, is a design pattern for UI test automation. Each page of the application, or each significant component such as a header or a modal, gets a class. The class stores the locators of the elements on that page and exposes methods that describe what a user can do there, such as login or searchFor. Tests then call these methods and contain assertions and flow, but no locators. The result is that when the interface changes, you update one page class instead of dozens of tests, and tests read like descriptions of user behaviour. Without POM, locators are copied through many tests and maintenance becomes the main cost of automation.
| Aspect | Without POM | With POM |
|---|---|---|
| Locators | Repeated in many tests | Defined once in the page class |
| Maintenance | Many files change when the UI changes | One page class changes |
| Readability | Low-level driver calls in tests | Tests read as user actions |
| Reuse | Copy and paste | Methods reused across tests |
| Separation | Mixed locators, actions and checks | Clear layers |
| Layer | Responsibility |
|---|---|
| Base page or base test | Shared driver handling, waits and helpers |
| Page classes | Locators and user actions of one page |
| Test classes | Scenarios and assertions |
| Utilities | Configuration, data readers, screenshots |
| Test data and resources | Files and environment settings |
A small shared parent class for page objects. Illustrative Java using Selenium 4.
import java.time.Duration;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;
public abstract class BasePage {
protected final WebDriver driver;
private final WebDriverWait wait;
protected BasePage(WebDriver driver) {
this.driver = driver;
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
protected WebElement visible(By locator) {
return wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
}
protected void type(By locator, String text) {
WebElement el = visible(locator);
el.clear();
el.sendKeys(text);
}
protected void click(By locator) {
wait.until(ExpectedConditions.elementToBeClickable(locator)).click();
}
}
The page object hides locators and returns the next page after a successful action.
public class LoginPage extends BasePage {
private final By email = By.id("email");
private final By password = By.id("password");
private final By loginButton = By.id("login");
private final By error = By.cssSelector(".error-message");
public LoginPage(WebDriver driver) { super(driver); }
public LoginPage open(String baseUrl) {
driver.get(baseUrl + "/login");
return this;
}
public DashboardPage loginAs(String user, String pass) {
type(email, user);
type(password, pass);
click(loginButton);
return new DashboardPage(driver);
}
}
Selenium offers PageFactory with the @FindBy annotation to initialise elements declared as fields. It reduces boilerplate and can cache or lazily locate elements. Many teams prefer plain By locators with explicit waits, as in the example above, because they are simple, work well with dynamic pages and are easy to debug. Check the current Selenium documentation for the status of PageFactory in your version before standardising on it, and apply whichever approach your team picks consistently.
| Locator | Stability | Note |
|---|---|---|
| Dedicated test attribute (data-test) | High | Best, agree with developers to add them |
| ID | High if not auto-generated | Fast and clear |
| Name or accessible label | Medium to high | Tied to meaning, not layout |
| CSS selector | Medium | Keep short and specific |
| XPath with positions | Low | Breaks easily with layout changes |
| Component | Typical methods |
|---|---|
| Header or navigation bar | openMenu, search, goToCart |
| Modal dialog | confirm, cancel, readMessage |
| Data table | getRowCount, findRowByText, sortBy |
| Date picker | selectDate, clearDate |
A throwaway script for one-time use. A very small project with one or two pages. In these cases keep the code simple, and introduce page objects when duplication starts to hurt.
Ready to design Selenium page objects that actually survive UI changes? Explore Uncodemy's Software Testing course or book a free demo and learn from industry trainers.