Skip to content

web: a soft hyphen or zero-width space stays in a name, so toHaveAccessibleName fails on a link getByRole found by that name #2491

In progress

Description

@gagarinyury

What happened

getByRole('link', { name: 'Datenschutzerklärung' }) finds <a href="#">Datenschutz&shy;erklärung</a>: Playwright drops U+00AD and U+200B before it matches a name. The tree keeps them, so toHaveAccessibleName('Datenschutzerklärung') on the same locator fails:

locator: getByRole("link", name: "Datenschutzerklärung")
expected: accessible name "Datenschutzerklärung"
observed: name "Datenschutz­erklärung" (match count 1)

Soft hyphens are common on German and Dutch sites, and zero-width spaces in CMS text. The agent reads the name with the hidden character too.

Reproduction

https://github.com/gagarinyury/e2e-repros/tree/main/invisible-name

Steps to reproduce

  1. npm install in the repo root, then cd invisible-name
  2. npx e2e run
  3. Both tests pass toHaveCount(1) and fail toHaveAccessibleName.

Expected: both pass.

Versions

e2e 0.25.0, @e2e-dev/web 0.17.0, Node 25.2.1, macOS. Also on main at 7c1b2b2.

Engine

@e2e-dev/web

Anything else

Chrome's accessibility tree keeps both characters. The tree already names the way getByRole matches when the two differ (inert text, icon glyphs), so I'd follow Playwright here. I have the fix with a crosscheck fixture and can send the PR.

Activity

  1. okwasniewski commented on Nov 29, 2026

    @okwasniewski
    Member

    Automated triage (AI), not yet read by a maintainer.

    Confirmed on main 7c1b2b258. Playwright's role matching drops U+200B and U+00AD from a name before it compares. The web tree's name exit, withoutGlyphs in packages/web/src/in-page/read-semantics.ts, only replaced icon glyphs, and core normalizeText only collapses whitespace. So getByRole finds Datenschutz&shy;erklärung by the plain word, while the tree name, and toHaveAccessibleName along with it, keeps the hidden character. This is a real problem on German/Dutch sites and with CMS text, and the agent reads the hidden character too.

    #2495 fixes it at that exit, with a crosscheck fixture that fails without the fix. Text matchers (toHaveText) are not part of that PR.

  2. added
    bug
    web
    needs:maintainer-decision
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds:maintainer-decisionweb

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions