the page's locators, usually ReturnType<typeof homeLocators>
the page's locators, usually ReturnType<typeof homeLocators>
the Playwright page
OptionallocatorFactory: LocatorFactory<L>
builds the page's locators; omit for a page with none
ReadonlylocatorsThe page's locators, built by the factory passed to the constructor.
ReadonlypageThe Playwright page this object drives.
Waits for an element to be visible, then clicks it.
the element to click
Clicks an element that opens a browser dialog, answers the dialog and returns what it said.
If no dialog opens, it waits for the project's actionTimeout, or the test timeout when no
actionTimeout is set (Playwright's default), then fails.
the element to click
accept (OK) or dismiss (Cancel). Default "accept"
OptionalpromptText: string
the text to enter when accepting a prompt
the dialog's type and message
Clicks an element and waits for the response it triggers, for actions whose only visible result comes after a request (an item removed, a list refreshed).
the element to click
the response to wait for: a URL, a pattern, or a predicate
the response
Asserts a locator matches at least one element, e.g. that a results list isn't empty.
matches zero or more elements
Optionalmessage: string
shown if the check fails
soft by default; see ExpectOptions
Asserts how many elements a locator matches.
matches zero or more elements
the expected number; 0 checks that none are on the page
Optionalmessage: string
shown if the check fails
soft by default; see ExpectOptions
Asserts the names of the files chosen in a file input.
the <input type="file">
the expected file names, in order; [] for none
Optionalmessage: string
shown if the check fails
Asserts an element is hidden or not on the page.
the element to check
Optionalmessage: string
shown if the check fails
soft by default; see ExpectOptions
Asserts a form control fails the browser's own validation (required, type="email", ...),
i.e. its validationMessage is not empty. The wording differs per browser and language, so
it is never compared.
the input, select or textarea
Optionalmessage: string
shown if the check fails
soft by default; see ExpectOptions
Asserts (soft) an element's text.
the element, or elements, to check
the expected text; an array checks each matched element in order
Asserts (soft) the page's title.
the full title, or a pattern
Asserts (soft) the page's URL.
the full URL, or a pattern such as /[?&]q=shoes/
Asserts a form control's current value.
the input, textarea or select
the expected value; "" for an empty field
Optionalmessage: string
shown if the check fails
soft by default; see ExpectOptions
Asserts an element is visible.
the element to check
Optionalmessage: string
shown if the check fails
soft by default, so one run reports every failed check; see ExpectOptions
Waits for a field to be editable, then replaces its value.
the input, textarea or editable element
the text to enter; numbers are converted to text
Returns the text of every element a locator matches. Does not wait: use it after the elements are known to be on the page.
matches zero or more elements
each element's visible text, trimmed
Waits for an element to be visible and returns its text.
the element to read
the element's visible text, trimmed
Navigates to a path relative to the project's baseURL. Waits for domcontentloaded, not
load: a stalled third-party script (ads, analytics) can hold back the load event
indefinitely, and web-first assertions wait for the elements a test needs anyway.
e.g. "/login". Default "/"
the main resource response, or null (see Playwright's page.goto)
From now on, dismisses every dialog the page opens and records its message, for checking later that none opened. Without a listener Playwright dismisses dialogs silently, so they would go unnoticed.
a list that fills as dialogs open; assert it is empty when no dialog was expected
Reloads the page. Waits for domcontentloaded, like BasePage.goto.
the main resource response, or null (see Playwright's page.reload)
The current query string, for checking URL state after a search or filter.
e.g. { q: "shoes", page: "2" }
Selects a dropdown option by its visible label.
the <select> element
the option's visible text
Chooses files in a file input.
the <input type="file">
one path or several; [] clears the input
Waits for the page's load event. BasePage.goto only waits for domcontentloaded, so
use this before acting on a control whose handler is bound by a script at the end of the
page: until that script runs, the control is visible but a click does nothing.
Base class for page objects. Page methods call these helpers (
this.click,this.fill, ...) rather than raw Playwright, so waits stay consistent. Add a helper here only when every page could use it and it takes locators as arguments; anything with page-specific names belongs on the page object.Example