Skip to main content
Glama

locator.candidates

Read-only

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

NameRequiredDescriptionDefault
nthNoZero-based index when the locator matches several elements.
refNoSnapshot ref (eNN) from page.snapshot.
textNoVisible text of the element.
xpathNoXPath expression.
frame_idNoFrame to search within; see page.list_frames.
selectorNoCSS selector; pierces shadow DOM.
target_idNoTarget handle (tgt_*). Omit for the active page.
browser_idNoBrowser handle (br_*). Omit to use the only running browser, or auto-launch one.
backend_node_idNoCDP backendNodeId, e.g. from inspector.pick.
test_id_attributeNoDefault "data-testid".

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.1/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true and openWorldHint=true, so safety is covered; the description adds genuinely new behavior by explaining that each candidate comes with a live match count and that ambiguous locators get a computed landmark scope rather than a .first() fallback. It does not describe what happens when no element matches the supplied identifier, which is the main unstated failure mode.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences, front-loaded with the core capability and then the ambiguity-handling detail. Minor editorializing ('which is the honest alternative to .first()') is close to fluff but does convey real design intent, so it mostly earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With ten optional parameters, no required fields, and no output schema, the description does well to describe the return shape (candidates plus per-locator match counts plus landmark scope). Remaining gaps are the identifier precedence rule and how frame_id/target_id interact with the lookup, both of which are only covered at schema level.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so all ten parameters are already documented in the schema. The description reinforces the four accepted element identifier forms (ref, selector, xpath, text) but adds no precedence rule for supplying more than one, which is the semantics an agent actually needs. Baseline 3 is appropriate when the schema carries the parameter burden.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The definition states a precise resource (durable locator candidates for a given element) and enumerates the strategy families returned: role plus accessible name, label, text, test id. It also scopes the tool by intent — the honest alternative to .first() — so an agent can separate it from locator.check, which implies verification after failure.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The timing guidance is explicit and directive: 'Use this before writing a Playwright test or a scenario, not after it fails.' That gives a clear when-to-use plus a when-not. It stops short of naming a specific sibling tool to reach for instead once a locator has already failed.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools