new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Playwright · API reference · all subjects

page/methods

36 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Page.exposeFunction parameters and purpose

Page.exposeFunction exposes a function to the page's JavaScript context. It takes two parameters: name (string) - the name of the function on the window object, and callback (function) - a callback function which will be called in Playwright's context. Available since v1.8.

Page.fill discouraged in favor of Locator.fill

Page.fill is discouraged. Users should use locator-based Locator.fill instead. To send fine-grained keyboard events, use Locator.pressSequentially.

Page.frame return type and parameters

Page.frame returns null or Frame. It returns the frame matching the specified criteria. Either name or url must be specified. In JavaScript, it takes frameSelector as string or object with optional name (string) and url (string, RegExp, URLPattern, or function). In Python it takes optional name and url parameters. In C# and Java it takes name or uses frameByUrl.

Page.frameByUrl method

Page.frameByUrl returns null or Frame. It returns the frame with matching URL. Takes url parameter (string, RegExp, or function receiving URL object as boolean). Available in C# and Java since v1.9.

Page.frameLocator return type and usage

Page.frameLocator returns a FrameLocator. When called without a selector, the search starts in any frame on the page (main frame or any iframe). Takes optional selector parameter (?string). When not specified, locator is matched in any frame on the page. Available since v1.17.

Page.frames return type

Page.frames returns Array<Frame>. It returns an array of all frames attached to the page. Available since v1.8.

Page.getAttribute discouraged and return type

Page.getAttribute returns null or string. It returns element attribute value. This method is discouraged; users should use locator-based Locator.getAttribute instead. Parameters: selector (input selector), name (string - attribute name to get). Options: strict, timeout, signal. Available since v1.8.

Page.getByAltText method

Page.getByAltText returns Locator. It locates elements by their alt text. Takes text parameter and optional exact option (boolean). Available since v1.27.

Page.getByLabel method

Page.getByLabel returns Locator. It locates elements by their associated label text. Takes text parameter and optional exact option (boolean). Available since v1.27.

Page.getByPlaceholder method

Page.getByPlaceholder returns Locator. It locates elements by their placeholder text. Takes text parameter and optional exact option (boolean). Available since v1.27.

Page.getByRole method

Page.getByRole returns Locator. It locates elements by their ARIA role. Takes role parameter (required since v1.27), and options: exact, description. Available since v1.27.

Page.getByTestId method

Page.getByTestId returns Locator. It locates elements by their test id attribute. Takes testId parameter (required since v1.27). Available since v1.27.

Page.getByText method

Page.getByText returns Locator. It locates elements by their visible text content. Takes text parameter and optional exact option (boolean). Available since v1.27.

Page.getByTitle method

Page.getByTitle returns Locator. It locates elements by their title attribute. Takes text parameter and optional exact option (boolean). Available since v1.27.

Page.goForward return type and behavior

Page.goForward returns null or Response. It returns the main resource response. In case of multiple redirects, the navigation resolves with the response of the last redirect. If cannot go forward, returns null. Navigates to the next page in history. Options: waitUntil, timeout, signal. Available since v1.8. Note: Back/Forward Cache (BFCache) testing is not supported.

Page.goto return type and behavior

Page.goto returns null or Response. It returns the main resource response. In case of multiple redirects, the navigation resolves with the first non-redirect response. The method throws an error for SSL errors, invalid URLs, timeout exceeded, unreachable server, or main resource failed to load. It does not throw for valid HTTP status codes including 404 and 500. Exceptions: navigation to about:blank or same URL with different hash returns null. Headless mode doesn't support navigation to PDF documents.

Page.goto parameters and options

Page.goto takes url parameter (string, must include scheme like https://). If Browser.newContext.baseURL is set and URL is a path, it gets merged via new URL() constructor. Options: waitUntil, timeout, signal, referer (string - takes preference over Page.setExtraHTTPHeaders). Available since v1.8.

Page.hideHighlight async method

Page.hideHighlight hides all locator highlight overlays previously added by Locator.highlight on this page. Available since v1.60.

Page.mainFrame return type

Page.mainFrame returns Frame. It returns the page's main frame. Page is guaranteed to have a main frame which persists during navigations. Available since v1.8.

Page.innerText return type and usage

Page.innerText returns string. It returns element.innerText. This method is discouraged in favor of Locator.innerText. Parameters: selector (input selector). Options: strict, timeout, signal. Available since v1.8.

Page.isChecked return type and usage

Page.isChecked returns boolean. It returns whether the element is checked. Throws if the element is not a checkbox or radio input. This method is discouraged in favor of Locator.isChecked. Parameters: selector (input selector). Options: strict, timeout, signal. Available since v1.8.

Page.isClosed method

Page.isClosed returns boolean. It indicates that the page has been closed. Available since v1.8.

Page.isEditable return type and usage

Page.isEditable returns boolean. It returns whether the element is editable. This method is discouraged in favor of Locator.isEditable. Parameters: selector (input selector). Options: strict, timeout, signal. Available since v1.8.

Page.isEnabled return type and usage

Page.isEnabled returns boolean. It returns whether the element is enabled. This method is discouraged in favor of Locator.isEnabled. Parameters: selector (input selector). Options: strict, timeout, signal. Available since v1.8.

Page.isHidden return type and usage

Page.isHidden returns boolean. It returns whether the element is hidden, the opposite of visible. A selector that does not match any elements is considered hidden. This method is discouraged in favor of Locator.isHidden. Parameters: selector (input selector). Options: strict. Note: timeout option is deprecated and ignored - this method does not wait. Available since v1.8.

Page.isVisible return type and usage

Page.isVisible returns boolean. It returns whether the element is visible. A selector that does not match any elements is considered not visible. This method is discouraged in favor of Locator.isVisible. Parameters: selector (input selector). Options: strict. Note: timeout option is deprecated and ignored - this method does not wait. Available since v1.8.

Page.locator return type and options

Page.locator returns Locator. Takes selector parameter (required). Options: hasNot (string or Locator), hasNotText (string or RegExp). Available since v1.14.

Page.opener return type

Page.opener returns null or Page. It returns the opener for popup pages and null for others. If the opener has been closed already, returns null. Available since v1.8.

Page.pdf return type and basic usage

Page.pdf returns Buffer. It generates a PDF of the page with print CSS media. To generate with screen media, call Page.emulateMedia first. By default generates PDF with modified colors for printing. Use -webkit-print-color-adjust CSS property to force exact colors. Available since v1.8.

Page.pdf width, height, margin units

Page.pdf width, height, and margin options accept values labeled with units. Unlabeled values are treated as pixels. Supported units: px (pixel), in (inch), cm (centimeter), mm (millimeter). Examples: page.pdf({width: 100}) sets 100 pixels, page.pdf({width: '10cm'}) sets 10 centimeters.

Page.pdf format options

Page.pdf format options are: Letter (8.5in x 11in), Legal (8.5in x 14in), Tabloid (11in x 17in), Ledger (17in x 11in), A0 (33.1in x 46.8in), A1 (23.4in x 33.1in), A2 (16.54in x 23.4in), A3 (11.7in x 16.54in), A4 (8.27in x 11.7in), A5 (5.83in x 8.27in), A6 (4.13in x 5.83in).

Page.pdf parameter options detailed

Page.pdf parameters: path (optional path to save PDF), scale (0.1 to 2, default 1), displayHeaderFooter (boolean, default false), headerTemplate (HTML with classes: date, title, url, pageNumber, totalPages), footerTemplate (same format as headerTemplate), printBackground (boolean, default false), landscape (boolean, default false), pageRanges (string like '1-5, 8, 11-13', default empty means all), format (default Letter), width (string or float), height (string or float), margin (object with top, right, bottom, left - all optional, default 0), preferCSSPageSize (boolean, default false), tagged (boolean, default false), outline (boolean, default false).

Page.pickLocator return type and usage

Page.pickLocator returns Locator. It enters pick locator mode where hovering over page elements highlights them and shows the corresponding locator. Once the user clicks an element, the mode deactivates and the Locator for the picked element is returned. Available since v1.59.

Page.querySelector return type and usage

Page.querySelector returns null or ElementHandle. It finds an element matching the specified selector within the page. If no elements match, returns null. This method is discouraged in favor of Page.locator. To wait for an element, use Locator.waitFor. Aliases: query_selector (Python), $ (JavaScript). Available since v1.9.

Page.querySelectorAll return type and usage

Page.querySelectorAll returns Array<ElementHandle>. It finds all elements matching the specified selector within the page. If no elements match, returns empty array. This method is discouraged in favor of Page.locator. Aliases: query_selector_all (Python), $$ (JavaScript). Available since v1.9.

Page.reload return type and behavior

Page.reload returns null or Response. It reloads the current page in the same way as if the user triggered a browser refresh. Returns the main resource response. In case of multiple redirects, the navigation resolves with the response of the last redirect. Options: waitUntil, timeout, signal. Available since v1.8.

Give your agent this brain