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 action triggers click event on parent element

See original GitHub issue

Current behavior:

In my test I do a cy.contains('button', '<button-text>').click() the the “click” event is being triggered on the parent of what I’ve selected. Most of the events are triggered on the element I’ve grabbed, except for “pointerup”, “mouseup” and “click”.

image

Desired behavior:

The “click” event should be triggered on the button element

Steps to reproduce: (app code and test code)

Versions

Cypress 3.5.0 Windows 10 Chrome 77

This did not occur on Cypress 3.3.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
belevcommented, Nov 20, 2019

In our team we had the same issues with this behaviour. I don’t see anything specific in our setup for the failing tests. Previously we were using version 3.4.1, after updating to 3.6.1 the test started failing and the target element for the click event is not the correct one.

I don’t know what is the difference but using { force: true } patched the issue temporary and the target element is the correct one.

Another temporary solution is to invoke the click on the element itself: cy.get(.some-button).then(button => button.click());

Additional observations from our case: We had opened modal in which some radio buttons should be clicked. The only difference from passing to failing test is the height of the modal.

0reactions
jennifer-shehanecommented, Aug 19, 2020

Unfortunately we have to close this issue as there is not enough information to reproduce the problem. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

Please comment in this issue with a reproducible example and we will consider reopening the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

trigger parent click event when child is clicked - Stack Overflow
You dont need to trigger element click events when child elements are clicked, the click event bubbles up the dom tree if you...
Read more >
JavaScript: Preventing Parent Event When Child Event Is ...
When the onClick is triggered in my child element, I want to stop the propagation to my parent element's onClick event.
Read more >
Element: click event - Web APIs | MDN
An element receives a click event when a pointing device button (such as a mouse's primary mouse button) is both pressed and released...
Read more >
Trigger an onClick event outside the child element, works for ...
1. Add click eventListener to the parent div · 2. Exclude the child div · 3. Remove the click eventListner on component unmount...
Read more >
Capture only parent's onClick event in React | bobbyhadz
Add an onClick event handler to the parent element. · Check if event.target is equal to event.currentTarget . · If the two elements...
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