Cypress does not always executes click on element

For those whore are using cypress version since/after "6.x.x"

You could use { force: true } like:

cy.get("YOUR_SELECTOR").click({ force: true });

but this might not solve it ! The problem might be more complex, that’s why check below

My solution:

cy.get("YOUR_SELECTOR").trigger("click");

Explanation:

In my case, I needed to watch a bit deeper what’s going on. I started by pin the click action like this:

enter image description here

Then watch the console, and you should see something like:
enter image description here

Now click on line Mouse Events, it should display a table:
enter image description here

So basically, when Cypress executes the click function, it triggers all those events but somehow my component behave the way that it is detached the moment where click event is triggered.

So I just simplified the click by doing:

cy.get("YOUR_SELECTOR").trigger("click");

And it worked 🎉

Hope this will fix your issue or at least help you debug and understand what’s wrong.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)