Node
Node is a common interface representing an element on a web page.
It provides queries to inspect the element’s properties, attributes, content, and to find sub-elements.
Both Page
and Element
types implement this interface.
Definition
Fields
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"
.