SoftwareTestPilot
Automation TestingPublished: 9 min read

Page Object Model Locator Strategy — Patterns That Scale

How senior SDETs organise locators inside Page Objects: naming conventions, base page classes, dynamic locators, and the mistakes that make POM unmaintainable.

Avinash Kamble
Founder & QA Engineer at SoftwareTestPilot
Reviewed by Priyanka G.
Share:XLinkedInWhatsApp

2026-07-17 · By Avinash Kamble, reviewed by Priyanka G.

The Page Object Model (POM) works — until your POM classes turn into 2,000-line dumpsters that nobody wants to touch. These are the patterns that keep POMs healthy at scale.

Rule 1 — One class per meaningful UI area

Don't create one giant HomePage. Split by user intent: LoginPage, CheckoutPage, OrderSummary. A good rule: if two features would be released independently, they deserve separate POM classes.

Rule 2 — Locators as readonly fields, not methods

export class LoginPage {
  constructor(private page: Page) {}
  readonly email    = this.page.getByRole('textbox', { name: 'Email' });
  readonly password = this.page.getByRole('textbox', { name: 'Password' });
  readonly submit   = this.page.getByRole('button',  { name: 'Sign in' });
}

Fields are declarative and easy to scan. Methods for high-level actions only.

Rule 3 — Dynamic locators via functions

row(customerName: string) {
  return this.page.getByRole('row').filter({ hasText: customerName });
}

Use functions when the locator needs runtime data. Never string-concatenate raw XPath.

Rule 4 — Base page for cross-cutting concerns

Put navbar, footer, toast, and modal helpers in a BasePage. Every page extends it. Avoids the classic bug where three different POMs each define their own closeToast().

Rule 5 — No assertions inside Page Objects

POM methods return data or navigate; assertions live in tests. This lets one POM serve happy-path and error-path tests without duplicated logic.

Generate POM classes automatically

Paste any HTML block into the XPath & CSS Selector Generator and click "Export Page Object". It produces a fully typed class for Playwright TypeScript, Selenium Java, or Cypress JavaScript with sensible field names.

Frequently asked questions

1.Should POM classes contain assertions?
No. Assertions belong in tests so one POM can support many scenarios.
2.How do I handle repeated locators like table rows?
Expose a function that takes runtime data and returns a scoped locator (e.g. row(customerName)).
3.Is POM outdated in 2026?
No. Alternatives like Screenplay exist but POM remains the industry default and integrates cleanly with Playwright, Selenium, and Cypress.
4.How big is too big for a POM class?
If it exceeds ~300 lines, split it. Multiple small POMs beat one god-class.
Keep going

Practice these questions

Rehearse Selenium and Playwright automation questions covering framework design, waits, locators and CI/CD.

Found this useful?
Share:XLinkedInWhatsApp

Was this article helpful?

Keep building your QA edge

Continue reading

Join the QA Community

Connect with fellow testers, share job leads, and get career advice.

Premium QA Resources

Stop Reinventing the Wheel. Upgrade Your QA Arsenal.

Take your testing skills from beginner to Lead Engineer. Supercharge your daily workflow with our premium digital resources.

  • Ready-to-use testing strategy templates
  • Advanced API & UI automation guides
  • ⏱️ Save 10+ hours a week on test planning
4.9/5 rating
Explore All Products

⭐⭐⭐⭐⭐ Trusted by 1,000+ Software Test Pilots • Instant Access