The Page Object Model in Selenium, Explained the Way the A4Q Exam Tests It

Mike K· ISTQB-Certified Tester, ExamCaliber Editorial Team·

Page objects are a K4 learning objective on the A4Q Selenium 4 Tester exam. Here is the four-layer model, the Selenium project's own rules, and the page-object-vs-wrapper trap that scenario questions are built on.

The Page Object Model (POM) is a design pattern for UI test automation in which every screen, or every reusable part of a screen, is represented by one class that knows how to interact with it, so that tests only say what they want done. In the A4Q Selenium 4 Tester Foundation syllabus it is learning objective STF4-3, graded K4, the highest cognitive level the syllabus uses: you are expected to analyse a GUI and decide how to split it into page objects, not just recite the definition. This article explains the pattern the way the exam looks at it, what the most common code examples get wrong, and how to tell a page object from a class that merely wraps WebDriver.

What problem does the Page Object Model solve?

A Selenium test that talks to the driver directly has three kinds of knowledge glued together: the business flow it checks, the locators of the elements it touches, and the synchronisation logic that makes those interactions reliable. Change any one of them and you edit the test. Multiply that by two hundred tests that all log in through the same form, and a single renamed id becomes an afternoon of search-and-replace.

The A4Q syllabus frames this as a maintainability problem before it ever mentions Selenium. Chapter 4, Maintainability of TAS and Test Scripts, argues that a manual tester adds context for free (they notice a disabled button and investigate), while a script has none, so any "intelligence" has to be programmed in. The more of it you push into individual scripts, the more fragile they get. The recommended move is to shift that intelligence up into the framework, into reusable functions with a single point of repair. Page objects are the pattern that gives those reusable functions a home and a name.

Page Object Model layers: test, page objects, components and wrappers, locators and driver

The four layers, and what is allowed in each

Most tutorials draw POM as two boxes, tests and page classes. In practice a maintainable Selenium suite has four layers, and the exam's K4 questions are about knowing which layer a given line of code belongs to.

  • Test layer. States intent and checks results: add item, apply coupon, expect total 90.00. It never contains a locator, a WebDriverWait, or a call on driver. If a test needs to know that a button is a <button> and not an <a>, the abstraction has leaked.

  • Page object layer. One class per screen or per meaningful state of a screen. Its public methods are the actions a user can perform there (apply_coupon, open_order) and the facts a user can read there (coupon_error, total). It hides locators and waits behind those methods.

  • Component and wrapper layer. Pieces that appear on many pages (header, cookie banner, date picker, data grid) get their own objects, and low-level actions that need synchronisation (click_when_ready, type_and_confirm) live in wrapper functions shared by every page object. This is where the syllabus wants your wait mechanisms (STF4-2) to sit, not scattered across tests.

  • Locator and driver layer. Exactly one definition per element, usually a constant next to the page object that uses it. When the front end renames a class, you change one line. Which locator language to use for that line is the subject of Stable Selenium Locators: CSS vs XPath; POM decides where the locator lives, that article decides what it says.

The rule of thumb the diagram ends with is worth memorising for the exam: a UI change should be fixed in exactly one layer, and the test layer should never be that layer.

Five rules the Selenium project itself gives

The Selenium documentation on page object models is short, and every one of its rules turns into a plausible exam question.

  1. Methods return page objects. login_page.login_as(user) returns a HomePage, because that is where a successful login lands. Navigation is modelled as a return type, so a test reads as a chain of screens. This is the point our A4Q certification guide flags as a favourite question: why does a page object return another page object? Because the next page is the result of the action, and the type documents the expected flow.

  2. Different outcomes are different methods. A login that should fail returns a LoginPage with an error visible, so you write login_expecting_failure(user) rather than one method with a boolean flag. The page object does not guess what the test wanted.

  3. Assertions belong in tests, with one exception. A page object may verify, in its constructor or an explicit check, that the browser really is on the page it represents; that is a precondition, not a test. Everything else, such as the total is 90.00, is the test's job. A page object full of assert statements is a test in disguise, and it cannot be reused by a test that expects a different result.

  4. A page object does not have to be a whole page. Modern web apps are built from components, and so should the model be. A HeaderBar object used by twenty page objects is still a page object in the syllabus's sense: an abstraction of part of the GUI.

  5. Expose behaviour, not elements. Returning a WebElement from a page object hands the caller a locator-bound, stale-prone handle and defeats the purpose. Return data (str, Decimal, a list of names) or another page object.

Page object or wrapper class? The distinction the exam is testing

The most common failure in real code, and the most common trap in K4 questions, is a class that has the shape of a page object but the content of a driver wrapper. It looks like this: LoginPage.enter_username(text), LoginPage.enter_password(text), LoginPage.click_login(). Three methods, three elements, one-to-one. The test still knows the order of the steps, still knows there are two fields and a button, and still breaks when the form gains a "remember me" checkbox that must be ticked for the flow to succeed.

A page object models what a user does, at the user's level of granularity: login_as(user). The user does not think in terms of "enter username"; they think in terms of logging in. If the form later adds a step, login_as absorbs it and no test changes. When a question shows you two class designs and asks which is the better abstraction of the GUI, this is the criterion: does the public method name describe a user goal, or an HTML element?

Two supporting tells: a good page object has fewer public methods than the screen has interactive elements, and its method names contain no element words (button, field, dropdown, click).

PageFactory, @FindBy, and what not to over-learn

Nearly every Java tutorial ranks "Page Factory" alongside POM as if they were siblings. They are not. POM is a design pattern that exists in every language; PageFactory is a Java support class that initialises fields annotated with @FindBy so you can write driver.findElement less often. The Python bindings have no equivalent, and the .NET bindings dropped theirs from the core package years ago. The pattern survives fine without it: a locator tuple plus a small find helper does the same job with less magic and no lazy-proxy surprises.

For the exam this matters in one direction only. The syllabus asks you to analyse a GUI and use page objects to abstract it; it does not ask you to reproduce PageFactory.initElements from memory. If a question mentions @FindBy, treat it as an implementation detail inside the page object layer, and answer the design question underneath.

Where page objects end and keyword-driven testing begins

Chapter 4 pairs page objects with STF4-4, applying keyword-driven principles, also at K4. The two are not alternatives; they are consecutive layers. A page object gives you login_as(user) and apply_coupon(code). A keyword-driven framework exposes those same actions as vocabulary (Login As, Apply Coupon) that a non-programmer can arrange in a table. Every keyword's implementation is a call into a page object; without page objects underneath, keywords end up wrapping raw locators, and the whole maintainability argument collapses one level down.

If an exam scenario describes a team of manual testers who must author automated checks without coding, the answer is a keyword layer on top of page objects, not instead of them.

How this appears on the A4Q exam

The exam has 40 multiple-choice questions, a pass mark of 26, and 60 minutes (75 for non-native speakers); the full format lives on the A4Q Selenium Tester certification page. A4Q publishes no per-chapter question counts, so nobody can honestly tell you "expect three POM questions". What we can say is that chapter 4 carries 150 of the 840 syllabus minutes and two of its four learning objectives are K4, which means scenario questions rather than definitions. Typical shapes:

  • A short description of a screen (a search bar, a results grid with paging, a filter panel) followed by four proposed class designs; you choose the one that best abstracts the GUI.

  • A code fragment from a test that contains a By.XPATH or a WebDriverWait, followed by what is wrong with this design?

  • A page object method that returns void after a navigation action, followed by what should it return instead?

  • A class with assertEquals inside, followed by which principle does this violate?

Our chapter 4 practice set currently holds 73 questions on maintainability, waits, page objects and keyword-driven design, and each of the six full mocks mixes chapter 4 items with the rest of the syllabus. Every answer option carries a rationale, so a wrong pick on which layer owns the wait tells you why, not just that you missed. Start with mock exam 1 if you have never sat a timed A4Q paper; the free result page shows each question with all four options explained.

A short checklist before you call a class a page object

  • Its public methods are named after user goals, not HTML elements.

  • It returns other page objects after navigation and plain data after reads, never WebElement.

  • It contains no assertions about business results, at most a check that it is on the right page.

  • Every locator it uses is defined once, in one place, and appears in no test.

  • Waits happen inside it or in a shared wrapper, never in the test that calls it.

  • It can be reused by a test that expects the opposite outcome without modification.

If a class passes all six, it will pass the exam's K4 scrutiny too, and, more usefully, it will still compile after the next front-end redesign.

Este artículo forma parte de nuestro contenido sobre A4Q Selenium Tester (Foundation).

Frequently asked

What is the Page Object Model in Selenium?

A design pattern in which each screen, or each reusable part of a screen, is represented by one class whose public methods are the actions a user can perform there and the facts a user can read there. Tests call those methods and never touch locators, waits or the WebDriver directly.

Is the Page Object Model on the A4Q Selenium Tester Foundation exam?

Yes. In the A4Q Selenium 4 Tester Foundation syllabus v3.0 it is learning objective STF4-3 in chapter 4, Maintainability of TAS and Test Scripts, at cognitive level K4: analyse a GUI and use page objects to abstract it. Expect scenario questions, not definitions.

What is the difference between Page Object Model and Page Factory?

POM is a language-independent design pattern. PageFactory is a Java support class that initialises fields annotated with @FindBy. Python has no equivalent and .NET dropped it from the core bindings, so the pattern does not depend on it.

Should a page object contain assertions?

Only one kind: a check that the browser is on the page the object represents. Assertions about business results belong in the test, otherwise the page object cannot be reused by a test that expects a different outcome.

Why does a page object method return another page object?

Because a navigation action lands the user on a new screen, and returning that screen's page object documents the expected flow and lets a test read as a chain of pages, for example login_as(user) returning a HomePage.

Does a page object have to represent a whole page?

No. Components that appear on many pages, such as a header, cookie banner or data grid, get their own objects, and page objects compose them. The syllabus term is an abstraction of the GUI, not literally a page.

MK
Mike K
ISTQB-Certified Tester, ExamCaliber Editorial Team

Part of the ExamCaliber editorial team. Every ExamCaliber question and rationale is written and reviewed by hand against the current syllabus — never scraped from exam dumps.