Introduce "Accessible Name" locator strategy #1440
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At TPAC 2019, folks working in ARIA and WebDriver discussed ways to extend WebDriver in order to help web developers learn and enforce best practices in accessibility. While discussing the prospect of new commands based on the APG, a more generic feature came up: the ability to select elements according to accessible name.
Today, it's easy for web developers to write UI tests with a "whatever works" mindset. Without a good amount of experience and forethought, the CSS selectors they choose to target elements can easily be broken by benign refactoring. In order to keep their tests passing, developers have to perform the additional maintenance work of updating selectors. Not only is this distracting and inefficient, but it's somewhat dangerous. Editing tests while refactoring diminishes developers' ability to verify equivalent functionality and increases the likelihood of regression.
Because an element's accessible name is directly exposed to end users, it is less subject to change than many of the implementation details upon which a CSS selector can rely. Web developers could use a locator strategy based on this to write tests that are more resilient to changes in their application code.
Like many accessibility best practices, web developers don't always use accessible names correctly (or at all). The promise of more resilient tests could help incentivize developers to make their applications more accessible in this way.
There are some concerns about exposing this capability to the DOM generally, both in terms of performance and security. @minorninth and @alice (the principle contributors to the Accessibility Object Model) can probably speak more to that. It's my understanding that integration with WebDriver is much more feasible. At TPAC, @cookiecrook mentioned that this WebKit and/or Safari already make this available in some privileged context.
Could a "accessible name" locator strategy fit in the WebDriver specification? If so, is there some existing algorithm we can reference?
Preview | Diff