Selenium: Page Object Model Evaluating POM vs Direct Scripting

Learning Objective: Compare the Page Object Model (POM) with direct scripting to understand trade-offs in readability, reuse, and long-term maintenance.

What’s the difference?

Direct scripting means writing all your selectors and actions directly in the test file.
POM (Page Object Model) organizes this logic into reusable classes for each page.

Example:

Direct script:

driver.find_element(By.ID, "username").send_keys("user1")
driver.find_element(By.ID, "password").send_keys("mypassword")
driver.find_element(By.ID, "login-button").click()

POM:

login_page = LoginPage(driver)
login_page.login("user1", "mypassword")

With POM, your test focuses on what the user does, not how to click each button.

Why POM scales better

As your test suite grows, these differences matter more:

Feature Direct Scripting Page Object Model (POM)
Readability Mixed logic/selectors; verbose Test logic reads like user workflow
Maintainability Duplicate code, many update points One point of update per page/component
Reuse of actions Limited, often copied Highly reusable methods
Scalability Painful as codebase grows Designed to handle growth
Adapting to UI changes Tedious, error-prone Quick, low-risk, centralized updates

Code Comparison: Updating a Selector

If the login button ID changes:

Direct script:

# Update everywhere:
driver.find_element(By.ID, "login-button").click()

POM:

# Update once in LoginPage class:
LOGIN_BUTTON = (By.ID, "sign-in")

All tests using that page now work without any other changes.

When to use each approach

🏗️ POM turns your tests into reusable building blocks that can grow with your application.

Final Takeaway

Direct scripting is fast to start, but POM is built to last. If you’re writing more than a few tests, POM helps you:

📘 Good tests are like good documentation—they should tell a clear story and be easy to keep up to date.

Knowledge check

❓ Which is the main advantage of updating a selector in the Page Object Model, compared to direct scripting?

❓ In which situation might direct scripting make sense even if you are familiar with POM?