Skip to content

Click on a disabled button with nested elements is silently ignored #34

Closed
@isaacplmann

Description

@isaacplmann
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions