Skip to content

[🚀 Feature]: ARIA role-based element location - Built this for fun, wondering if it makes sense for Selenium? #16135

Open

Description

@JoanEsquivel

Description

What would you like Selenium to support or do differently?

Hey! I built something for a personal project and thought I'd share to see if it might be useful for Selenium in general.

What I was trying to solve:
I wanted a more reliable way to select elements in my tests, so I decided to use ARIA roles and accessibility attributes. They're less likely to change compared to classes or IDs, and it also aligns better with how users interact with the app.

What I ended up building:

# I made this work in my local project
username = driver.find_element_by_role("textbox", name="Username")
submit_btn = driver.find_element_by_role("button", name="Submit")
all_buttons = driver.find_elements_by_role("button")

It's been working great for my testing. I used some Chrome DevTools Protocol stuff for the accessibility tree and fell back to DOM parsing when that's not available.

My implementation: https://github.com/JoanEsquivel/python-se/blob/main/tests/test_get_by_role.py

Why I'm posting this:
I'm honestly not sure if this is something that would make sense for Selenium as a whole, or if I'm just solving a problem that's specific to my use case. Maybe other people have better ways of handling this?

I've been using it and it's been solid across Chrome, Firefox, and Edge, but I have no idea what the "right" way to implement something like this in Selenium would be.

Questions I have:

  • Is this kind of functionality something Selenium would even want?
  • Are there technical reasons this wouldn't work well as a core feature?
  • Am I missing some existing way to do this that I just haven't found?

I've never contributed to an open source project before, so I'm not really sure how this works or if this is even the right place to suggest something like this.

Have you considered any alternatives or workarounds?

My implementation:

  • Extends WebDriver instances with the new methods
  • Uses CDP when available, falls back to DOM parsing
  • Handles accessible name resolution (aria-label, aria-labelledby, etc.)
  • Has basic type safety with enums

The code is all in my repo: https://github.com/JoanEsquivel/python-se

But honestly, I'm sure there are much better ways to architect this if it were going into Selenium proper. I just hacked together what worked for my needs.

Activity

  1. added
    I-enhancement
    A-needs-triaging
    on Aug 6, 2025
  2. selenium-ci commented on Aug 6, 2025

    @selenium-ci
    Member

    @JoanEsquivel, thank you for creating this issue. We will troubleshoot it as soon as we can.

    Selenium Triage Team: remember to follow the Triage Guide

  3. added
    B-devtools
    C-py
    on Aug 6, 2025
  4. AtharvaDesai13 commented on Aug 6, 2025

    @AtharvaDesai13
  5. diemol commented on Aug 6, 2025

    @diemol
    Member

    People are overusing ChatGPT for this. Marking the comment above as spam.

  6. cgoldberg commented on Aug 6, 2025

    @cgoldberg
    Member
  7. cgoldberg commented on Aug 6, 2025

    @cgoldberg
    Member

    I've never contributed to an open source project before, so I'm not really sure how this works or if this is even the right place to suggest something like this.

    Yes, this is the correct place. For a non-trivial change, the best place to start is a Feature Request for discussion. If people are open to your feature/idea, the next steps would be: fork the repo, create a branch with your changes, create a Pull Request.

    For more information on development and contributing, see:

    For help, you can also join IRC/Slack:

  8. JoanEsquivel commented on Aug 6, 2025

    @JoanEsquivel
    Author

    Thanks for your response @cgoldberg I will check the links provided and try BiDi when I have a chance.

  9. added
    A-needs decision
    on Aug 7, 2025
  10. ms6073 commented on Aug 8, 2025

    @ms6073

    People are overusing ChatGPT for this. Marking the comment above as spam.

    This does seem like the lazy man's way of making Selenium work like Playwright!
    So for the op, css locators can already do what you mention above. In .NET we would use the following: By.CssSelector("textbox[name='Username']") .

  11. JoanEsquivel commented on Aug 8, 2025

    @JoanEsquivel
    Author

    Hey, appreciate the input! I agree that CSS selectors are powerful, but this isn't about targeting attributes; it's about accessing the accessibility tree, not the DOM.

    The goal here is to use the browsing context.locateNodes BiDi command to query elements the way assistive tech sees them: by role, name, and other semantic properties. It covers things like aria-labelledby, computed names, and actual role mapping, stuff that CSS can’t reach.

    I discovered it using Cypress & Playwright, but I thought Selenium could take advantage of the BiDi protocol(initially with CDP, and now using BiDi) :)

  12. cgoldberg commented on Aug 8, 2025

    @cgoldberg
    Member

    css locators can already do what you mention above

    Not really.

    css selectors can find certain elements, but that is very different than the feature presented here (OP's code already falls back to using css selectors when necessary). This is an interesting way to locate elements via CDP or BiDi without parsing the DOM when possible.

  13. ms6073 commented on Aug 8, 2025

    @ms6073

    This is an interesting way to locate elements via CDP or BiDi without parsing the DOM when possible.

    Thanks for the clarification. I obviously get a FAIL in the area of reading comprehension today.

  14. github-actions commented on Feb 5, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 14 days.

  15. added
    J-stale
    on Feb 5, 2026
  16. removed
    J-stale
    on Feb 5, 2026
  17. pujagani commented on Jun 5, 2026

    @pujagani
    Contributor

    Appreciate your effort here! Given @AutomatedTester 's work on generating BiDi commands and events from the WebDriver CDDL spec for python, this should be possible using WebDriver BiDi.

  18. github-actions commented on Dec 5, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 14 days.

  19. added
    J-stale
    on Dec 5, 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

    A-needs decisionA-needs-triagingB-devtoolsC-pyI-enhancementJ-stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions