Blog
Page Object Model in Selenium & Cypress: Complete Guide

Rishabh Kumar
Published on

Table of contents
Lorem ipsum
Lorem ipsum
Lorem ipsum
Lorem ipsum
Lorem ipsum
The Page Object Model (POM) has been the gold standard for organizing test automation code since the early days of Selenium. It separates page structure from test logic, making tests more maintainable and readable. But POM comes with costs: boilerplate code, class proliferation, and ongoing maintenance as applications evolve. This guide covers POM implementation in both Selenium and Cypress, explains best practices, and reveals when modern alternatives eliminate the need for Page Objects entirely.
What is the Page Object Model?
The Page Object Model is a design pattern that creates an abstraction layer between test code and page structure. Each page (or significant component) in your application becomes a class containing:
Element locators for that page
Methods representing actions users can perform
Methods returning page state information
Tests interact with Page Objects rather than directly with elements. When the UI changes, you update the Page Object; tests remain unchanged.
The Problem POM Solves
Without Page Objects, tests directly embed element locators:
When the login button selector changes from .login-btn to .submit-button, every test using that selector requires modification. With dozens or hundreds of tests, this becomes unsustainable.
How POM Solves It
Page Objects centralize locators and actions:
Tests become cleaner and selector changes require single-point updates:
Page Object Model in Selenium
Basic Selenium POM Structure
A standard Selenium Page Object includes:
Page specific classes extend the base:
Selenium POM Best Practices
1. Return Page Objects from Navigation Methods
When actions navigate to new pages, return the corresponding Page Object:
This enables fluent chaining:
2. Avoid Assertions in Page Objects
Page Objects should describe page capabilities, not test expectations. Keep assertions in test files:
3. Handle Dynamic Elements
For elements that appear conditionally or after delays:

Page Object Model in Cypress
Cypress does not require POM the way Selenium does because its command chaining and automatic retry reduce many problems POM addresses. However, many teams still apply the pattern for organization.
1. Cypress POM Implementation
Cypress Page Objects typically use JavaScript classes or plain objects:
Tests import and use the Page Object:
2. Cypress Custom Commands Alternative
Many Cypress users prefer custom commands over Page Objects:
Usage:
Cypress POM Best Practices
1. Use Getter Methods for Elements
Getters re-query the DOM each time, avoiding stale references:
2. Return "this" for Method Chaining
Enable fluent interfaces by returning "this":
3. Handle Component Reuse
For components appearing across multiple pages, create component classes:
The Hidden Costs of Page Object Model
While POM improves test organization, it introduces costs that compound over time.
1. Boilerplate Proliferation
Every page requires:
A Page Object class file
Locator definitions for each element
Methods for each action
Wait handling for dynamic content
A medium complexity application with 50 pages generates thousands of lines of Page Object code before a single test runs.
2. Maintenance Burden
When UI changes occur:
Identify affected Page Objects
Update locators
Potentially modify method signatures
Update tests if return types change
Run tests to verify fixes
Organizations report spending 40% to 60% of automation effort on maintenance, with significant time in Page Object updates.
3. Locator Fragility
POM centralizes locators but does not make them resilient. A Page Object with:
Still breaks when the form structure changes. The single-point-of-update benefit helps, but brittle locators remain brittle.
4. Abstraction Overhead
Page Objects add a layer of indirection. Debugging requires:
Understanding the test failure
Navigating to the Page Object
Examining the locator
Checking the method implementation
Potentially reviewing the base class
This mental overhead slows troubleshooting compared to simpler test structures.
The Modern Alternative: Natural Language Testing
AI native platforms eliminate Page Object complexity by removing the need for element locators entirely.
How It Works
Instead of defining locators and methods, describe actions in natural language:
Traditional Page Object approach:
Natural Language approach:
No Page Objects. No locators. No boilerplate. The platform identifies elements through intelligent analysis of text, position, semantic attributes, and context.
Self Healing Eliminates Maintenance
When UI changes occur:
Page Object approach: Update locators manually, verify fix, redeploy
AI native approach: Self healing automatically adapts to changes. The platform recognizes "Place Order button" through multiple signals. When the button's class changes, it remains identifiable through text content, position, and surrounding context.
Virtuoso QA achieves approximately 95% self healing accuracy, eliminating the maintenance burden that makes Page Objects necessary in the first place.
Migrating Existing Tests
Organizations with existing Selenium or Cypress test suites can migrate using Virtuoso QA's GENerator, which converts framework code into natural language journeys:
Selenium Page Objects → Natural language steps
Cypress custom commands → Natural language steps
Test logic preserved, locator complexity eliminated
Migrated tests gain self healing capabilities immediately without rewriting from scratch.
Conclusion - Choose the Right Approach
Page Object Model served test automation well for over a decade. It remains the best practice for teams committed to Selenium or Cypress. But POM is a workaround for a fundamental limitation: element identification through brittle locators.
AI native testing addresses the root problem. Natural language element identification and self healing eliminate the need for locator management. Page Objects become unnecessary when elements identify themselves through what users see rather than DOM structure.
Virtuoso QA enables:
Natural Language Programming: Describe tests in plain English
Self Healing: Automatic adaptation when UI changes (95% accuracy)
Zero Page Objects: No locator management, no boilerplate
10x Faster Test Creation: Focus on what to test, not how to locate
GENerator Migration: Convert existing Selenium and Cypress tests
The question is not whether Page Objects are useful. They are. The question is whether you want to maintain them forever.

Related Reads
Frequently Asked Questions
Should I use Page Object Model for new Selenium projects?
Is Page Object Model necessary in Cypress?
How do I organize Page Objects for large applications?
Can Page Objects and AI native testing coexist?
What happens to Page Objects when my application changes significantly?
How does Natural Language testing handle complex interactions?






