-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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.