
How to Hover on Elements in Cypress
Although Cypress does not support officially a cy.hover
command, there is some workaround that may work for your specific case.
Triggering mouse over events
One way is to trigger a mouseover
event using the trigger
command:
cy.get('nav').trigger('mouseover');
Forcing show
If using the mouseover
event does not work, you can also try to force showing the element:
cy.get('.hidden').invoke('show').click();
cy.get('.hidden').click({ force: true });
Using custom commands
Lastly, you can also try using the rightclick
command, with the combination of defining it as a new custom command. You can of course do this for the above two workarounds too:
// Define in your `support/commands.js`
Cypress.Commands.add('hover', selector => {
cy.get(selector).rightclick();
});
// Later in your tests you can call:
cy.get('nav').hover();
Want to learn Cypress from end to end? Check out my Cypress course on Educative where I cover everything:


Resources:

Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies: