Cypress does not always executes click on element

https://github.com/cypress-io/cypress/issues/2928 helped me.

cy.get('[data-qa="select_workers-list"]'.contains('+ New Worker').trigger('mouseover').click();

2022 here and tested with cypress version: "6.x.x" until "10.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.


For me this code worked:

Inside your click methods add : { force: true } It will make force click.

Also add: cy.wait(150) to beforeEach or before click where your test fails.

It is just workaround not a solution.

Link to Cypress Issue

Also i saw this alternative:

cy.get('#query-btn').invoke('width').should('be.gt', 0)

cy.get('#query-btn').invoke('width').should('be. greaterThan', 0)

But it didnt work out for me. Maybe will be usefull for someone!