TestingLibraryElementError: Unable to find an element with the text: x
getBy* found no matching element in the rendered output.
Seen on:
React
Meaning
The text is split across elements, rendered asynchronously, differs in case/whitespace, or the component never rendered it. The error prints the current DOM to compare.
Common causes
- Element appears after async work (use findBy)
- Text split across nodes
- Exact text/case mismatch
- Wrong query (getByText vs getByRole)
⚡ Quick fix
- Use await findByText for async UI
- Use a regex or { exact: false }
- Prefer getByRole with name for accessibility-based queries
Detailed fix by platform
React
await screen.findByRole('button', { name: /save/i });
How to diagnose
- DOM — What does the printed DOM contain?
- Timing — Async?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026