Snowy
Snowy

Reputation: 59

Cypress click button and keep the mouse on the button

I am testing a dropdown button, when I click the button, the dropdown menu shows up. However, if the mouse leaves the button and menu, the dropdown menu will hide. If I use click, it will fail with reason the button detached on the DOM. If I use click({force:true}), it will throw the ResizeObserver loop limit exceeded exception. Then I use realClick the button, no fail or errors, but still, the dropdown menu can not be seen. I think it's because the mouse is in other position so it hides (or maybe some other weird reasons). I tried realHover before or after the realClick, still no dropdown menu. How can I keep the mouse on the button after realClick?

Upvotes: 0

Views: 1265

Answers (2)

Alapan Das
Alapan Das

Reputation: 18634

How about you use mousedown and then mouseup.

cy.get('selector').trigger('mousedown')
cy.get('selector').trigger('mouseup')

Upvotes: 0

ItsNotAndy
ItsNotAndy

Reputation: 573

There are a few different ways of doing this.

cy.get('.menu-item').trigger('mouseover').realClick()

Check https://docs.cypress.io/api/commands/hover#Trigger for more info.

Upvotes: 3

Related Questions