locator.candidates
Find durable Playwright locators for any element, with current match counts and a unique landmark scope when ambiguous. Use before writing tests to avoid brittle selectors and .first().
Instructions
Given any element (ref, selector, xpath, text), the locators a durable test could use for it - role plus accessible name, label, text, test id - each with how many elements it actually matches right now. When a locator is ambiguous it computes the landmark scope that makes it unique, which is the honest alternative to .first(). Use this before writing a Playwright test or a scenario, not after it fails.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "locator.candidates"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nth | No | Zero-based index when the locator matches several elements. | |
| ref | No | Snapshot ref (eNN) from page.snapshot. | |
| text | No | Visible text of the element. | |
| xpath | No | XPath expression. | |
| frame_id | No | Frame to search within; see page.list_frames. | |
| selector | No | CSS selector; pierces shadow DOM. | |
| target_id | No | Target handle (tgt_*). Omit for the active page. | |
| browser_id | No | Browser handle (br_*). Omit to use the only running browser, or auto-launch one. | |
| backend_node_id | No | CDP backendNodeId, e.g. from inspector.pick. | |
| test_id_attribute | No | Default "data-testid". |