dom-testing-library icon indicating copy to clipboard operation
dom-testing-library copied to clipboard

TestingLibraryElementError: Unable to find an element with the text - This could be because the text is broken up by multiple elements

Open por14571-jochoa opened this issue 3 years ago • 8 comments

Hello, I have a problem, i try to find some elements and gets a problem with the library, it doesn't find the queries.

If someone know about how to fix this problem.

TestingLibraryElementError: Unable to find an element with the text: /Texto./i. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

image


❓ Support Forums

  • Discord https://discord.gg/testing-library
  • Stack Overflow https://stackoverflow.com/questions/tagged/react-testing-library

ISSUES WHICH ARE QUESTIONS WILL BE CLOSED

por14571-jochoa avatar Dec 15 '22 22:12 por14571-jochoa

Closing this this because it isn't an issue. If you need some help try our discord server or stackoverflow and share a reproducible example.

timdeschryver avatar Dec 16 '22 18:12 timdeschryver

Thanks, I can solve the problem.

por14571-jochoa avatar Dec 16 '22 19:12 por14571-jochoa

@por14571-jochoa How did you solve this problem?

jed212 avatar Feb 15 '24 07:02 jed212

Uh oh! @snolan-ethika, the image you shared is missing helpful alt text. Check https://github.com/testing-library/dom-testing-library/issues/1196#issuecomment-1998406417.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

github-actions[bot] avatar Mar 14 '24 20:03 github-actions[bot]

@por14571-jochoa How did you solve this problem?

I stumbled upon this thread, it kind of pointed me in the right direction finally... hope it helps you out https://stackoverflow.com/a/65951158

snolan-ethika avatar Mar 14 '24 22:03 snolan-ethika

Thanks, I can solve the problem.

Hello, tell us how you solved it, please

thamaraRD avatar Apr 04 '24 04:04 thamaraRD

Thanks, I can solve the problem.

Hello, tell us how you solved it, please

@thamaraRD I was able to solve this by manually setting the component's template with the necessary info, it doesn't feel right having to do this, but it was getting me by. I didn't spend a lot of time figuring out another way, but this helped me get it going.

ref: https://stackoverflow.com/a/65951158

snolan-ethika avatar Apr 04 '24 15:04 snolan-ethika

For anyone having this issue, if your div has a text like "Read our docs" and you search for getByText("docs") it will cause the error. getByText expects for the entire text inside the node, so the correct is getByText("Read our docs")

Victor-Ross avatar Apr 25 '25 02:04 Victor-Ross