Page
Represents a single tab or window in a web browser. The Page type provides methods to interact with the web page loaded in that tab. It implements the Node interface, giving access to element querying capabilities, and also offers page-specific information and actions like accessing URL, title, content, cookies, etc.
Definition
Fields
browserVersion
: String
A string identifying the browser name and version. Example: "Chrome/138.0.0.0"
Example
content
: String
The full HTML content of the page. This is equivalent to the document’s outerHTML.
Example
cookies
: [Cookie]
Retrieves cookies for the current page’s URL or specified URLs.
If no URLs are provided, cookies for the current page URL are returned.
If URLs are provided, only cookies for those specific URLs are returned.
Example: cookies(urls: ["https://example.com", "https://another.com"])
Arguments
urls
: [String] - An optional list of URLs to retrieve cookies for. If omitted, cookies for the current page’s URL are returned. Example:["https://www.example.com", "https://sub.example.com"]
pdf
: Download
Generates a PDF representation of the current page.
Returns a Download object which can contain a URL to the PDF or its Base64 encoded data.
Example: pdf(options: { format: A4, landscape: true, printBackground: true })
Arguments
options
: PDFOptions - Options to customize the PDF output, such as paper size, orientation, margins, and more. SeePDFOptions
for details.
response
: Response
Information about the main resource response for the page.
This includes status, headers, and other details of the HTTP response that loaded the page.
May be null if the page was loaded from content directly (e.g., via page(content: "...")
).
status
: Int
The HTTP status code of the main page response. Example: 200 for success, 404 for not found. May be null if the page was not loaded via an HTTP request (e.g., a data URL).
storageState
: StorageState
The current storage state of the page, including cookies, local storage, and IndexedDB data. This is a snapshot of the current state and can be used for session persistence or transfer.
title
: String
The title of the current page, as specified in the <title>
HTML tag.
url
: URL
The current URL of the page. If the page has been redirected, this will be the final URL.
userAgent
: String
The browser’s user agent string for this page.
This can be overridden when the page is created or via a specific mutation.
Example: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
viewport
: Viewport
Information about the page’s viewport, including its dimensions and device characteristics.
element
: Element
Queries the current context (Page or Element) for a single element matching the specified criteria.
If multiple elements match, the first one is returned. Returns null if no element is found.
Supports various selector strategies including CSS selectors, text content, ARIA roles, and more.
Example: element(selector: ".my-class", text: "Submit")
Arguments
selector
: String - The CSS selector for the element. Example:"#username"
for<input id="username" />
.text
: String - Finds an element by its text content. Example:"Login"
for<button>Login</button>
.role
: String - Finds an element by its ARIA role. Example:"button"
for<div role="button">Submit</div>
.label
: String - Finds an element by its ARIA label. Example:"Search button"
for<button aria-label="Search button"><svg/></button>
.placeholder
: String - Finds an element by its placeholder text. Example:"Enter your email"
for<input placeholder="Enter your email" />
.altText
: String - Finds an element by its image alt text. Example:"Company logo"
for<img alt="Company logo" src="..." />
.title
: String - Finds an element by its title attribute. Example:"Close dialog"
for<span title="Close dialog">X</span>
.testId
: String - Finds an element by its data-testid attribute. Example:"submit-button"
for<button data-testid="submit-button">Go</button>
.filter
: ElementFilterOptions - Advanced filtering options for the element.
elements
: [Element]!
Queries the current context (Page or Element) for all elements matching the specified selector.
Supports various selector strategies including CSS selectors, text content, ARIA roles, and more.
Returns an empty list if no elements are found.
Example: elements(selector: "div.product-item")
Arguments
selector
: String - The CSS selector for the element. Example:"#username"
for<input id="username" />
.text
: String - Finds an element by its text content. Example:"Login"
for<button>Login</button>
.role
: String - Finds an element by its ARIA role. Example:"button"
for<div role="button">Submit</div>
.label
: String - Finds an element by its ARIA label. Example:"Search button"
for<button aria-label="Search button"><svg/></button>
.placeholder
: String - Finds an element by its placeholder text. Example:"Enter your email"
for<input placeholder="Enter your email" />
.altText
: String - Finds an element by its image alt text. Example:"Company logo"
for<img alt="Company logo" src="..." />
.title
: String - Finds an element by its title attribute. Example:"Close dialog"
for<span title="Close dialog">X</span>
.testId
: String - Finds an element by its data-testid attribute. Example:"submit-button"
for<button data-testid="submit-button">Go</button>
.filter
: ElementFilterOptions - Advanced filtering options for the element.
ariaSnapshot
: String
Provides a snapshot of the ARIA (Accessible Rich Internet Applications) properties of the element. This can be useful for accessibility testing and understanding the element’s semantics. The snapshot includes the element’s role, name, and other properties.
attribute
: String
Retrieves the value of a specified attribute for the element.
Returns null if the attribute does not exist.
Example: attribute(name: "href")
on an <a>
tag, or attribute(name: "data-custom")
on any element.
Arguments
name
: String! - The name of the attribute to retrieve. Example:"class"
,"id"
,"value"
,"src"
.
attributes
: JSONObject
Retrieves all attributes of the element as a JSON object.
Each key in the object is an attribute name, and its value is the attribute’s string value.
Example: { "id": "myElement", "class": "active important", "data-value": "123" }
boundingBox
: BoundingBox
Returns the bounding box of the element in pixels, relative to the main frame’s viewport. Returns null if the element is not visible.
innerHTML
: String
Retrieves the inner HTML content of the element.
This includes all HTML markup within the element.
Example: For <p>Hello <b>world</b></p>
, innerHTML would be "Hello <b>world</b>"
.
innerText
: String
Retrieves the visible text content of the element, excluding hidden text but including text from the shadow DOM.
This is similar to what a user would see on the page.
Example: For <p>Hello <b>world</b></p>
, innerText might be "Hello world"
.
markdown
: String
Attempts to convert the HTML content of the element into Markdown format. Useful for extracting structured text content.
screenshot
: Download
Captures a screenshot of the element.
Returns a Download object containing the URL or Base64 data of the screenshot image.
Example: screenshot(options: { type: PNG, omitBackground: true })
Arguments
options
: ScreenshotOptions - Options to configure the screenshot, such as image type, quality, or clipping. SeeScreenshotOptions
.
textContent
: String
Retrieves the text content of the element and all its descendants, including <script>
and <style>
tags.
Example: For <p>Hello <b>world</b></p>
, textContent would be "Hello world"
.