ADocumentation Index
Fetch the complete documentation index at: https://mintlify.com/l-xiaoshen/handstage/llms.txt
Use this file to discover all available pages before exploring further.
Locator is the primary way to interact with elements on a page. You obtain one by calling page.locator(selector), and from there you can click, fill, hover, and more. Locators are intentionally lazy — the selector is not evaluated until you call an action, and it is re-evaluated on every action. This means you never hold a stale element reference across navigations.
Creating a locator
Pass a CSS selector or an XPath expression topage.locator(). The locator is bound to the page’s main frame.
Supported selector syntax
Handstage supports three selector types, detected automatically from the string prefix:- CSS selectors — standard CSS like
#id,.class,input[type="text"],div > span - XPath expressions — strings that start with
/or(, such as//button[@id='submit'],/html/body/div[1], or(//td)[3]. You can also use an explicitxpath=prefix. - Text selectors — strings prefixed with
text=, such astext=Submit. Matches elements containing the given text.
css=, xpath=, text= to override automatic detection.
Interacting with elements
Locators expose a set of action methods. Each one resolves the element at call time, performs the action, and releases the remote object.Targeting the nth match
By default, a locator acts on the first element that matches the selector. Usenth(index) to target a specific match by zero-based index.
count():
Shadow DOM piercing
Handstage can pierce shadow DOM boundaries automatically. Pass{ deep: true } in the locator options to search inside shadow roots when evaluating CSS selectors.
The
deep option applies to CSS selectors. XPath expressions already traverse shadow roots natively in Handstage’s resolver.Locators are lazy
Locators do not resolve the DOM element when you callpage.locator(). The element is looked up fresh on every action call. This has two practical implications:
- You can create a locator before the element exists in the DOM and call actions on it later.
- You never need to worry about stale element references across navigations — the locator always finds the current live element.
Frame locators for iframes
To interact with elements inside an iframe, usepage.frameLocator(selector) to scope subsequent locators to that frame. You can chain frame locators for nested iframes.
frameLocator accepts the same CSS and XPath selector syntax as locator. It resolves the iframe element and scopes all chained locator calls to its document.
Error handling
When a locator cannot find a matching element, Handstage throwsHandstagesElementNotFoundError. When the element exists but is not visible (for example, its bounding box has zero area), actions like click() and hover() throw ElementNotVisibleError.
Common patterns
Wait for an element before interacting
Wait for an element before interacting
Use
page.waitForSelector() when an element appears asynchronously. Once it resolves, you can interact with it through a locator.Check visibility before acting
Check visibility before acting
Call
isVisible() to guard against interacting with hidden elements.Read an input's current value
Read an input's current value
Use
inputValue() to read the current value of an input, textarea, select, or contenteditable element.Select an option from a dropdown
Select an option from a dropdown
Use
selectOption() on a <select> element. Pass one or more option values.