Problem
css-selector-generator produces fragile positional selectors like:
:root > :nth-child(2) > :nth-child(5) > :nth-child(2) > :nth-child(2)
These are useless for an AI coding agent — they break on any DOM change and convey no meaning.
Proposed Selector Priority
data-testid or data-cy attributes (test frameworks)
aria-label or role attributes (accessibility)
- React component name (already captured in
reactComponent.name)
- ID-based selector (
#submit-btn)
- Text content match (for buttons/links with unique text)
- Class-based selector (
.hero-section .cta-button)
- nth-child chain (last resort, current behavior)
Implementation
- Replace or configure
css-selector-generator in src/content/element-selector.ts
- Use the React component name as the primary identifier when available
- Add a
humanReadableSelector field alongside the existing selector
- Formatter should prefer
humanReadableSelector in output
Related
🤖 Generated with Claude Code
Problem
css-selector-generatorproduces fragile positional selectors like:These are useless for an AI coding agent — they break on any DOM change and convey no meaning.
Proposed Selector Priority
data-testidordata-cyattributes (test frameworks)aria-labelorroleattributes (accessibility)reactComponent.name)#submit-btn).hero-section .cta-button)Implementation
css-selector-generatorinsrc/content/element-selector.tshumanReadableSelectorfield alongside the existingselectorhumanReadableSelectorin outputRelated
🤖 Generated with Claude Code