002-locator-strategy

002-locator-strategy is a cursor rule for Cursor from azam-sdet/10xquality. It costs 0 tokens per session (1,402 once invoked), scanned A, original, MIT.

A set of rules for choosing reliable element locators in Playwright, the browser-testing tool. It ranks options such as input names, IDs, labels, test IDs, roles, and text, and defines how to handle repeated matches and dropdowns.

In plain words
What is it for?
Use it when writing or reviewing Playwright selectors for forms, buttons, dropdowns, and other web-page elements.
Why use it?
It reduces fragile tests caused by changing page styles, duplicate text, or selectors that point to the wrong control.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it when writing or reviewing Playwright selectors for forms, buttons, dropdowns, and other web-page elements.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/azam-sdet/10xquality/002-locator-strategy
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/azam-sdet/10xquality

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for 002-locator-strategy

README.md
[![agentmods](https://agentmods.dev/badge/rules/azam-sdet/10xquality/002-locator-strategy/github.svg)](https://agentmods.dev/rules/azam-sdet/10xquality/002-locator-strategy)
Your own site
<a href="https://agentmods.dev/rules/azam-sdet/10xquality/002-locator-strategy"><img src="https://agentmods.dev/badge/rules/azam-sdet/10xquality/002-locator-strategy/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for 002-locator-strategy

Your own site · 80×15
<a href="https://agentmods.dev/rules/azam-sdet/10xquality/002-locator-strategy"><img src="https://agentmods.dev/badge/rules/azam-sdet/10xquality/002-locator-strategy.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,402 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.01402
Opus 5 $0.00000 $0.00701
Sonnet 5 $0.00000 $0.00280
Haiku 4.5 $0.00000 $0.00140

Measured 9d ago against content hash 650920be8942, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

002-locator-strategy scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/002-locator-strategy.mdc · 134 lines

How it starts

The opening of the file, as written. The whole thing — 134 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Locator Strategy for Playwright Tests

Follow this priority order when selecting locators. Prefer stable, semantic selectors over brittle CSS.

Priority Order

Priority Strategy When to Use Example
1 input[name="..."] Form inputs with name attribute input[name="email"]
2 #id Element has a unique ID #submit-button
3 Label-based ancestor Form fields with associated labels getInputByLabel('Email')
4 [data-test="..."] Test IDs added for automation [data-test="submit-btn"]
5 getByRole() / getByText() Text-unique elements page.getByRole('button', { name: 'Submit' })
6 CSS with :has-text() Last resort when above fail button:has-text("Create")

Ambiguity Rules

  • NEVER use .first() on a has-text locator without verifying uniqueness. If the recorded hint shows ambiguity.sameText > 1, the same text appears in multiple elements. Use label-based disambiguation instead.
  • For dropdowns: Don't rely on the button/placeholder text (e.g., "Select..."). Multiple dropdowns may share the same placeholder. Always navigate from the field label.
  • For buttons at the bottom of forms (Cancel, Submit, Create): These are usually unique. button:has-text("Create") is safe when ambiguity.sameText === 1.

Label-Based Ancestor Navigation

Use label-based patterns when form fields have associated labels. This disambiguates elements that share the same data-test or placeholder text.

Input Fields

private getInputByLabel(labelText: string) {
  const label = this.page.locator(`label:has-text("${labelText}")`).first();
  return label.locator('xpath=ancestor::div[.//input][1]').locator('input');
}

// Usage
await this.getInputByLabel('Email').fill('[email protected]');

Dropdowns (Generic Pattern)

For dropdowns that use a trigger button (common in design systems), locate the trigger via the label's ancestor:

Read the full file on GitHub · 134 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 134 lines · 0 tokens per session scan A 650920be8942

Subscribe to this mod's changes

002-locator-strategy is a cursor rule published in the GitHub repository azam-sdet/10xquality (2 stars, last pushed 6mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,402 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.