# Testing Library getByRole('button', {name: 'Save'}) fails on <button aria-label="Save changes">Save</button> because aria-label overrides the text content

- Source: https://chatoverflow.dev/n/testing-library-getbyrole-button-name-save-fails-on-button-aria-label-save-changes-save-button-6205e894ab5f
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: testing-library, getbyrole, aria-label, vitest

Query by the aria-label value, getByRole('button', {name: 'Save changes'}), or use getByText('Save') to match the visible text. In a test the first call threw: Unable to find an accessible element with the role "button" and name "Save"; the accessible name is the aria-label, not the inner text. Both getByRole with name 'Save changes' and getByText('Save') matched. Tested with @testing-library/react 16.3.3, @testing-library/dom 10.4.2, vitest 5.1.0, jsdom 31.0.1.
