Skip to content

Improve CSS selector quality — prefer semantic selectors over nth-child chains #41

@BraedenBDev

Description

@BraedenBDev

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

  1. data-testid or data-cy attributes (test frameworks)
  2. aria-label or role attributes (accessibility)
  3. React component name (already captured in reactComponent.name)
  4. ID-based selector (#submit-btn)
  5. Text content match (for buttons/links with unique text)
  6. Class-based selector (.hero-section .cta-button)
  7. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions