click action triggers click event on parent element
See original GitHub issueCurrent 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”.
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:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top 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 >
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
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 to3.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.
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.