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
In this repository35 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ai-native-workflowSkill
- api-testingSkill
- common-tasksSkill
- configSkill
- data-strategySkill
- debuggingSkill
- enumsSkill
- fixturesSkill
- helpersSkill
- page-objectsSkill
- playwright-cliSkill
- pr-reviewerSkill
- refactor-valuesSkill
- skill-creatorSkill
- test-standardsSkill
- type-safetySkill
- ai-native-workflowSkill
- api-testingSkill
- common-tasksSkill
- configSkill
- data-strategySkill
- debuggingSkill
- enumsSkill
- fixturesSkill
- helpersSkill
- page-objectsSkill
- playwright-cliSkill
- pr-reviewerSkill
- refactor-valuesSkill
- selectorsSkill
- skill-creatorSkill
- test-standardsSkill
- type-safetySkill
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
- Very specific: line 19
Never XPath (page.locator('//...'), 'xpath=...').
- Distinctive: line 22
Every page object for a form or CRUD screen has feedback selectors: success, error, field validation, and toast, loading or empty state …
- Very specific: line 26
Read the URL: grep '^APP_URL' env/.env.${ENVIRONMENT:-dev}.
≈ “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.
Files
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 takesgetByLabel('Email')overgetByRole('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-cliis 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 fromenums/{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
- Read the URL:
grep '^APP_URL' env/.env.${ENVIRONMENT:-dev}. No env file → ask the human for the URL. playwright-cli open <APP_URL>, thenplaywright-cli snapshot; commands inplaywright-cli. Explore in the auth state the spec will run in: thechromiumproject starts signed in, so sign in through the login page first unless the spec callsresetStorageState(). The page fails to load or needs auth → stop perreferences/exploration-workflow.md.- 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.
- List the paths the page must support (happy, validation, error, edge); each path names the feedback locator that proves it.
- 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 perpage-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.
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
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.

