What this thread does
Do first: inspect the rendered roles with logRoles(container), then query the expected role using its accessible name and applicable semantic state.
Short answer
Diagnostic: Found multiple elements with the role
As of November 2026, DOM Testing Library 10.4.2 is the release reference. Default role queries exclude inaccessible nodes. The hidden option broadens inclusion. Read the missing-query role/name listing before broadening a selector. ByRole.
Choose / don't choose
- User-visible dialog flow: open it through awaited user interaction, then query its accessible controls. Don't use
hidden: trueto bypass a missing opening interaction. user-event. - Deliberate hidden-DOM assertion: choose
hidden: truewhen those excluded nodes are the actual subject. Don't assume their accessible name remains the same while hidden. - Same-role controls: choose name and supported state, or narrow the container. Don't choose an arbitrary array index to suppress ambiguity.
Not for: mocked HTTP responses; see mock-third-party-apis-msw-nock-go-tests.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
hidden | Default false; true includes tree-excluded elements, including aria-hidden="true" descendants | DOM Testing Library current docs | ByRole |
name | TextMatch; e.g. "Save" for the intended button | DOM Testing Library current docs | ByRole |
selected | true or false for a supported role, e.g. tab | DOM Testing Library current docs | ByRole |
checked | true or false for a supported role, e.g. checkbox; mixed is neither | DOM Testing Library current docs | ByRole |
expanded | Filter returned elements by expanded state with true or false | DOM Testing Library current docs | ByRole |
Example combinations: getByRole('tab', {name: 'Native', selected: true}), getByRole('checkbox', {name: 'Remember me', checked: true}), or getByRole('button', {name: 'Options', expanded: false}). Use the state supported by that role; these are separate selectors, not three simultaneous filters for every control.
Order of operations
1. Render and complete the interaction that exposes the interface. Await asynchronous appearance with the appropriate find query rather than adding hidden inclusion. Query behavior. 2. Use logRoles(container) to inspect implicit roles; read the failure's accessible names as well. Roles match literal names, not an inheritance hierarchy. Role diagnostics. 3. Confirm native markup, accessible name and state. A password input has no implicit role; use its label query instead of inventing a role. ByRole. 4. Assert the specific control and state. Keep hidden inclusion local to the assertion that requires it.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Found multiple elements with the role | The role query's getMultipleError returns this diagnostic | Narrow by accessible name/state or container; use a plural query only for an intended group | tagged query implementation |
Unable to find an accessible element | The queried accessible role/name was not found | Inspect role/name output; open or await the UI; include hidden nodes only deliberately | tagged query implementation, query behavior |
jgoux's October 27, 2021 report illustrates that a role match does not guarantee a name match for dynamic content. It concerns an older Cypress integration, not a current DOM Testing Library regression claim.
Missing
hidden: truedoes not establish visibility, interactability or browser accessibility correctness.- A control must actually expose the selected semantic state; a state filter cannot supply missing application semantics.
Checked
2026-11-12; DOM Testing Library 10.4.2 release, ByRole/query/accessibility/user-event docs, tagged role query implementation and jgoux's October 2021 issue read. No test commands executed.
Started from a post by @Testing Library, packaged by the editor. Original post