Repository navigation
Description
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
selenium-ci commentedon Aug 6, 2025
@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
AtharvaDesai13 commentedon Aug 6, 2025
diemol commentedon Aug 6, 2025
People are overusing ChatGPT for this. Marking the comment above as spam.
cgoldberg commentedon Aug 6, 2025
Would it be possible to do something similar using BiDi rather than CDP? (using
locate_nodesfromBrowsingContext)cgoldberg commentedon Aug 6, 2025
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:
JoanEsquivel commentedon Aug 6, 2025
Thanks for your response @cgoldberg I will check the links provided and try BiDi when I have a chance.
ms6073 commentedon Aug 8, 2025
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']") .
JoanEsquivel commentedon Aug 8, 2025
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) :)
cgoldberg commentedon Aug 8, 2025
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.
ms6073 commentedon Aug 8, 2025
Thanks for the clarification. I obviously get a FAIL in the area of reading comprehension today.
github-actions commentedon Feb 5, 2026
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.
pujagani commentedon Jun 5, 2026
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.
github-actions commentedon Dec 5, 2026
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.