selector-writing-guide

selector-writing-guide is a cursor rule for Cursor from verdexhq/verdex-mcp. It costs 115 tokens per session (6,040 once invoked), scanned A, original, Apache-2.0.

A rulebook for writing stable Playwright selectors, which are instructions that identify controls and content in browser tests. It recommends accessible roles and labels, short selector chains, and stable containers instead of positions or brittle text syntax.

In plain words
What is it for?
Use it while exploring pages, writing or repairing Playwright locators, debugging failed selectors, and testing forms, product grids, shops, or repeated interface patterns.
Why use it?
It helps prevent browser tests from breaking when page structure changes or when repeated elements appear in a different order.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/. Also seen: positional $N argument.

Good fit Use it while exploring pages, writing or repairing Playwright locators, debugging failed…

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/verdexhq/verdex-mcp/selector-writing-guide
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/verdexhq/verdex-mcp

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 selector-writing-guide

README.md
[![agentmods](https://agentmods.dev/badge/rules/verdexhq/verdex-mcp/selector-writing-guide.svg)](https://agentmods.dev/rules/verdexhq/verdex-mcp/selector-writing-guide)
Your own site
<a href="https://agentmods.dev/rules/verdexhq/verdex-mcp/selector-writing-guide"><img src="https://agentmods.dev/badge/rules/verdexhq/verdex-mcp/selector-writing-guide.svg" alt="Measured on agentmods" height="20"></a>
Per session 115 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 6,040 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.00115 $0.06040
Opus 5 $0.00057 $0.03020
Sonnet 5 $0.00023 $0.01208
Haiku 4.5 $0.00012 $0.00604

Measured 6d ago against content hash 9817b339b011, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

selector-writing-guide 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 6d 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.

.cursor/rules/selector-writing-guide.mdc · 852 lines

How it starts

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

Verdex Selector Writing Guide: From Exploration to Production-Ready Selectors

A comprehensive guide for writing stable, role-first Playwright selectors using Verdex MCP's progressive disclosure tools.


Table of Contents

  1. Core Principles
  2. The Verdex Workflow
  3. The Winning Pattern
  4. Tool Usage Guide
  5. Real-World Example Walkthrough
  6. Common Pitfalls & Solutions
  7. Selector Pattern Library
  8. Token Efficiency Guidelines
  9. Quick Reference

Core Principles

✅ Always Follow This Priority Order:

  1. Check uniqueness FIRST - If an element is unique on the page, don't over-scope
  2. Use Playwright built-in locators - getByRole(), getByTestId(), getByLabel(), etc.
  3. Container → Content → Role pattern - Scope to stable containers, filter by content, target by role
  4. Minimal chain depth - Keep selector chains ≤ 2-3 levels deep
  5. Role-first targeting - Always end with semantic roles when possible

❌ Never Do These:

  • Positional selectors: .nth(0), .first(), .last()
  • Old locator syntax: locator("text=..."), locator("role=...") (use getByText(), getByRole())
  • Parent traversal: .locator('..')
  • Excessive nesting: 4+ level chains like div > div > div > button
  • Class-only selectors: .locator('div.class1.class2.class3')
  • Filter in wrong place: Filtering buttons by text that's in sibling elements

The Verdex Workflow

Step-by-Step Process

graph TD
    A[1. browser_navigate] --> B[2. browser_snapshot]
    B --> C{Element Unique?}
    C -->|Yes| D[Use simple selector]
    C -->|No| E[3. resolve_container]
    E --> F{Found stable anchor?}
    F -->|Test ID/Landmark| G[Use as container]
    F -->|Generic divs| H[4. inspect_pattern]
    H --> I[5. extract_anchors if needed]
    I --> G
    G --> J[Generate selector]

Read the full file on GitHub · 852 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. 6d ago First seen · 852 lines · 115 tokens per session scan A 9817b339b011

Subscribe to this mod's changes

selector-writing-guide is a cursor rule published in the GitHub repository verdexhq/verdex-mcp (17 stars, last pushed 8mo ago), licensed Apache-2.0. It adds 115 tokens to every session and 6,040 once invoked, about $0.0006 per session on Opus 5. 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-30.