feat(locator): Resolve Elements with aria-owns and aria-controls as Children in getByRole Method #34334
+220
−5
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.
The
ariaChildren
option was added to thegetByRole
method in Playwright to enhance the ability to locate elements that are referenced byaria-owns
andaria-controls
attributes. By default, elements referenced by these attributes are not included in the search. This option allows developers to include these elements in their search.Why This Solution Was Implemented
ARIA attributes like
aria-owns
andaria-controls
are used to manage relationships between elements for accessibility purposes. Including these elements in the search helps in testing and validating these relationships.In complex web applications, elements might be referenced by ARIA attributes but not be direct children in the DOM. This option allows for more accurate element selection in such cases.
Example Usage
Consider the following DOM structure:
In this example, the
navigation
element ownsmenu1
andmenu2
via thearia-owns
attribute. To locate theServices
menu item, you can use theariaChildren
option.Code Example
Here is how you can use the
ariaChildren
option in Playwright: