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

[Bug]: getByRole() doesn't find <section> elements with title attribute #31428

Closed
developenguin opened this issue Jun 25, 2024 · 5 comments
Closed

Comments

@developenguin
Copy link

Version

1.44.1

Steps to reproduce

  1. Clone https://github.com/developenguin/playwright-region-query
  2. run npm install
  3. run npx playwright test

Expected behavior

I expect page.getByRole('region', { name: 'WWF History' }) to find the <section title="WWF History"> element.

Actual behavior

The element is not found.

Additional context

image

Screenshot of the DOM

Environment

System:
    OS: Linux 6.5 Linux Mint 21.3 (Virginia)
    CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900HX
    Memory: 51.63 GB / 62.50 GB
    Container: Yes
  Binaries:
    Node: 18.20.3 - ~/.nvm/versions/node/v18.20.3/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.3/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v18.20.3/bin/npm
  Languages:
    Bash: 5.1.16 - /usr/bin/bash
  npmPackages:
    @playwright/test: ^1.44.1 => 1.44.1
@pavelfeldman
Copy link
Member

pavelfeldman commented Jun 25, 2024

You need to set an explicit aria label as per
https://www.w3.org/TR/wai-aria-1.2/#region
Also see
https://www.w3.org/WAI/GL/wiki/Using_HTML5_section_element

@pavelfeldman
Copy link
Member

(It might be easier to use getByTitle in your case).

@developenguin
Copy link
Author

I did indeed get it working using getByTitle. However, since Chromium does report the name property in the Accessibility properties for the section, it was my expectation that getByRole would find it based on that:
image

But I guess that's not the case. I'll use aria-label then, thank you for your response!

@pavelfeldman
Copy link
Member

Chrome will sometimes step away from the spec and use accessible name heuristics. We'll check why they did it, but we seem to be correct as per the spec on this one.

@pavelfeldman
Copy link
Member

Closing as per above, please feel free to open a new issue if this does not cover your use case.

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

No branches or pull requests

2 participants