Click on a disabled button with nested elements is silently ignored
See original GitHub issuecypress-testing-library
version: 2.3.5cypress
version: 3.1.5node
version: 8.15npm
(oryarn
) version: yarn 1.12.3
Note: This issue is related to getByText
, but the problem is in the way it behaves in relation to cypress, not a bug in the actual getByText
function itself.
Relevant code or config
<button disabled>
<span>Hi</span>
</button>
What you did:
cy.getByText('Hi').click()
What happened: The span element was clicked, even though the button was disabled. The click is ignored by the button though, since it is disabled.
Workaround: You can revert to normal cypress commands and do this:
cy.contains('button', 'Hi').click();
Cypress will wait until the button is enabled before trying to click. Or if the timeout expires, it will throw an error.
Suggested solution:
I’m not sure? Silently failing seems like the wrong thing though. Perhaps I just shouldn’t use cy.getByText
to try to click on a button.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
React stopPropagation onClick for disabled button with nested ...
First click the button, then when it's disabled, click on either the loading icon (the <i> element) or the text Deleting which is...
Read more >testRigor English-language support documentation
It will issue click on the deepest element in the element tree that has the text. Specifying position on screen. It is possible...
Read more >Advanced Svelte: Reactivity, lifecycle, accessibility
Let's create a component that will be in charge of displaying the buttons and emitting the corresponding events. Create a new file, components/ ......
Read more >Bootstrap 5.0.2
Ignore it entirely and silence the deprecation warnings ... by nested elements (e.g., modals didn't transition when clicking buttons).
Read more >Changelog - Cypress Documentation
Fixed a regression introduced in Cypress 12 where cy.get() would ignore a null ... inside a .within() callback would silently select the first...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Interesting. I’ll verify later today and see if that is an issue in this library or in Testing Library DOM.
There had been many changes to this library since this issue was opened. I’ll also see if there original issue is still valid.
Thanks for all of this! If you could open an issue for us to discuss this that would be great! It would be good to get any potentially breaking changes implemented before we cut the next major release.