agentleFS
idavidov13idavidov13/agentic-playwright/.agents/skills/selectors/SKILL.md

selectors

Skill268 starsChanged 10 days agoMITView on GitHub

Use when choosing a locator for an element, writing or reviewing locators in a page object, or exploring the live app before any UI code. Not for the page-object class shape or registration (see `page-objects`) or for the CLI commands themselves (see `playwright-cli`).

  • Reads credentials

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never XPath (page.locator('//...'), 'xpath=...').

    line 19
  2. Distinctive:

    Every page object for a form or CRUD screen has feedback selectors: success, error, field validation, and toast, loading or empty state …

    line 22
  3. Very specific:

    Read the URL: grep '^APP_URL' env/.env.${ENVIRONMENT:-dev}.

    line 26

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Selectors

Critical

  • Priority order: getByRole > getByLabel > getByPlaceholder > getByText > getByTestId. Move to the next option only when the previous one is not feasible. One exception: a labelled form field takes getByLabel('Email') over getByRole('textbox', { name: 'Email' }).

    // CORRECT
    page.getByRole('button', { name: 'Submit' });
    // WRONG
    page.locator('.btn-primary');
  • Never XPath (page.locator('//...'), 'xpath=...'). CSS class or id selectors only as a last resort after every semantic option is ruled out.
  • Exploration with playwright-cli is mandatory before any selector is written. No guessing from wireframes, docs or screenshots. If the app cannot be reached or auth fails, stop and notify the human; never ship placeholder locators.
  • Strings inside getByText(...) come from enums/{area}/* (Messages.LOGIN_ERROR); the text is captured from the live app, never guessed (enums).
  • Every page object for a form or CRUD screen has feedback selectors: success, error, field validation, and toast, loading or empty state where the app shows them.

Procedure

  1. Read the URL: grep '^APP_URL' env/.env.${ENVIRONMENT:-dev}. No env file → ask the human for the URL.
  2. playwright-cli open <APP_URL>, then playwright-cli snapshot; commands in playwright-cli. Explore in the auth state the spec will run in: the chromium project starts signed in, so sign in through the login page first unless the spec calls resetStorageState(). The page fails to load or needs auth → stop per references/exploration-workflow.md.
  3. Walk the feature as a user: snapshot, act, snapshot. Trigger each form submit and CRUD action. Record every element's role, accessible name, label, placeholder or test id, and the exact text of every message.
  4. List the paths the page must support (happy, validation, error, edge); each path names the feedback locator that proves it.
  5. Choose each locator by the priority order (references/locator-choice.md), add the feedback locators (references/feedback-selectors.md), and write them into the class per page-objects.

References

  • references/exploration-workflow.md: what to observe at each state and the stop-and-notify protocol when the app is unreachable.
  • references/locator-choice.md: correct form per tier, exact and scoped matches, multi-match and "stale" symptoms, elements with no accessible name.
  • references/feedback-selectors.md: the feedback types to capture and the locator for each.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.