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.

cy.click() yields no error, but wrong element is clicked

See original GitHub issue

I previously reported erroneous behavior in regards to determining visibility. With #6000 and v3.8.2, this was indeed fixed, but it uncovered another issue.

Current behavior:

cy.get("...").click({ force: false }) no longer yields an error, but the click-handler of the DOM element is never invoked. If I however invoke it with force: true, its click-handler is invoked.

I modified Cypress with the patch shown below and was quite surprised to find that the actually clicked element is not the element described in the console as “Actual Element Clicked”. The actual element clicked is an ancestor of my subject, which does not have any click-handler at all.

diff --git a/packages/driver/src/cy/commands/actions/click.js b/packages/driver/src/cy/commands/actions/click.js
index f6e0cb7f5..c4add683e 100644
--- a/packages/driver/src/cy/commands/actions/click.js
+++ b/packages/driver/src/cy/commands/actions/click.js
@@ -207,6 +207,8 @@ module.exports = (Commands, Cypress, cy, state, config) => {
         onReady (fromElViewport, forceEl) {
           const clickEvents = mouse.click(fromElViewport, forceEl)
 
+          console.log(clickEvents);
+
           return {
             clickEvents,
           }

Desired behavior:

If cy.get("...").click({ force: false }) doesn’t yield an error, it should invoke the click-handler of the subject and not some other element determined by some heuristic.

Test code to reproduce

I’m having a hard coming up with a minimal example to reproduce the issue. I’m posting the output of the commands in hope that it will be enough to spark some ideas. If this is not enough, then I’ll give it another shot.

With force: false:

2020-01-15-135643_5360x1440_scrot

With force: true:

2020-01-15-135707_5360x1440_scrot

Versions

Cypress v3.8.2, Arch Linux, Chrome 79.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Jan 16, 2020

The idea behind this behavior is to mimic the behavior that the browser enforces when a real user clicks.

If a user in a real browser clicks on an element and mid-click another DOM element animates in front of where their mouse cursor is, the rest of the Mouse events will fire on the new element that is now directly behind the mouse cursor.

This is expected behavior with the correct workaround being to use force: true as you’ve noted which will force all Mouse events to be triggered on the DOM element specified.

I can see how the ‘Actual Element Clicked’ console log is a bit confusing though since some of the events were fired on another element.

That being said, there could be some weird edge case where this is doing funky things outside of what I just described. If that is the case - we’ll need a reproducible example provided to investigate.

0reactions
badeballcommented, Oct 29, 2020

Can you check if { force: true } works with 4.12.1 and API key empty?

With my Ubuntu 20.04, it doesn’t work.

Yes, I can check. FYI, in your screenshot, it appears you are not using force: true.

  • With v5.5.0 and force: false: wrong element is clicked
  • With v5.5.0 and force: true: correct element is clicked
  • With v4.12.1 and force: false: wrong element is clicked
  • With v4.12.1 and force: true: correct element is clicked
  • With v3.4.0 and force: false: correct element is clicked
  • With v3.4.0 and force: true: correct element is clicked

IE. there’s a regression somewhere after v3.4.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress does not always executes click on element
click() on it 2 or more times, I ensured it was first set in focus prior to being clicked. This fixed it for...
Read more >
click - Cypress Documentation
Click all elements with id starting with 'btn'​​ By default, Cypress will error if you're trying to click multiple elements. By passing {...
Read more >
cy.click() failed because this element is not visible: - You.com
I debug and found that "ensureNotDisabled" is getting callled and After evaluating subject.prop('disabled') it returns true which throws that error. Is any work ......
Read more >
A Better cy.each Iteration - Gleb Bahmutov
The test does not even wait for the number to be revealed before moving to the next table row and clicking the next...
Read more >
5 Things to Avoid When Writing Cypress Tests - Webiny
Learn how to avoid 5 common mistakes when writing Cypress tests that ... On the contrary, there is no doubt that End-to-End testing...
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