question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Click on a disabled button with nested elements is silently ignored

See original GitHub issue
  • cypress-testing-library version: 2.3.5
  • cypress version: 3.1.5
  • node version: 8.15
  • npm (or yarn) 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:closed
  • Created 5 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
NicholasBollcommented, Feb 26, 2020

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.

1reaction
kentcdoddscommented, Mar 6, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found