Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Ignore special characters like softhyphens when locating by name #34859

Open
lubomsky opened this issue Feb 18, 2025 · 4 comments
Open
Assignees
Labels

Comments

@lubomsky
Copy link

lubomsky commented Feb 18, 2025

🚀 Feature Request

We have exact attribute to match accessible name more or less strict. And that is handy.
But I encountered difficulties locating elements that contain special characters like soft hyphen or zero width space.
Of course I can provide full name with \u00AD, but it is not readable:
super\u00ADcali\u00ADfrag\u00ADilistic\u00ADexpial\u00ADidocious
vs
super­cali­frag­ilistic­expial­idocious

It would be nice to have another attribute working along with name and exact to handle those special non-printing/formatting characters.

Example

page.getByRole(AriaRole.COLUMNHEADER, 
               new Page.GetByRoleOptions().setName("super­cali­frag­ilistic­expial­idocious")
                                          .setIgnoreNonPrinting(true)) // or setIgnoreFormattingChars or whatever...
    .click();

or may be set to true as default (similarly to exact).

Chaining with setExact(true) may be tricky here - maybe its naming is not the best for the purpose.

Motivation

To have more capabilities for locating elements by accessible name, keeping in mind this advice:

When to use role locators
We recommend prioritizing role locators to locate elements, as it is the closest way to how users and assistive technology perceive the page.

Users don't see and assistive technology does not read "\u00AD" etc...

@lubomsky lubomsky changed the title [Feature]: Ignore special characters like softhyphens when locating by aria role name [Feature]: Ignore special characters like softhyphens when locating by name Feb 18, 2025
@mxschmitt mxschmitt transferred this issue from microsoft/playwright-java Feb 19, 2025
@Skn0tt
Copy link
Member

Skn0tt commented Feb 20, 2025

I'll discuss it with the team. This is probably the area in the code where we'd have to look implementation-wise:

const accessibleName = normalizeWhiteSpace(getElementAccessibleName(element, !!options.includeHidden));

@Skn0tt
Copy link
Member

Skn0tt commented Feb 20, 2025

How does your application end up with softhyphens in the accessible name, anyways?

@Skn0tt
Copy link
Member

Skn0tt commented Feb 20, 2025

getElementAccessibleName refers to "Flat strings" from the ARIA spec:

Flat string: A string of characters where all carriage returns, newlines, tabs, and form-feeds are replaced with a single space, and multiple spaces are reduced to a single space. The string contains only character data; it does not contain any markup.

I'd consider Softhyphens markup, so going by the spec we should probably remove them.

@Skn0tt
Copy link
Member

Skn0tt commented Feb 20, 2025

chromium seems to not remove them, but we discussed that we should

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants