How can I hover over an element and then click using Cypress


Emirhan Rose:

I would like to hover over the "My Account" button and click the "Login" button to open the popup. I have tried the code below but it didn't work. Does anyone know a way to handle this situation? thanks,

 Cypress.Commands.add('loginol', (email, password) => { 
     cy.get('#myAccount').click()
     cy.get('#myAccount').trigger('mouseover')
     cy.wait(3000)
     cy.get('#login').click()
     cy.get('#email').type(email)
     cy.get('#password').type(password)
     cy.get('.btn.full.btn-login-submit').click()

 })

I have uploaded a picture of the case it helps:

"Girişeup (My Account)" button"Girişeup (My Account)" button

After that, the "Girişeup (Login)" button hovers below itAfter that, the "Girişeup (Login)" button hovers below it

Website My Work: https://www.hepsiburada.com/

Tschallacka:

You don't have a unique ID, assign a unique ID to your element

From the source code of your website:

duplicate ID

So what happens is you trigger the widget, first the mouseover of the My Account item, the widget container. In this item you don't have any event constraints, in the second item tag along with its bindingid="myAccount"

IDs must be unique

To fix make your button similar id id="myAccount_button"and target, in your test script.

Below is a snippet that mimics your website. It doesn't show the menu.

$('#myAccount').trigger('onmouseover');
#menu {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="myAccount">
  <div id="myAccount" onmouseover="$('#menu').show()" onmouseout="$('#menu').hide()">
     my account
  </div>
</div>
<div id="menu">
a<BR/>
c<BR/>
d<BR/>
e<BR/>
</div>

Here is the snippet with revisions. As you can see, the menu is displayed here because the ID is unique and can be targeted.

$('#myAccount_button').trigger('onmouseover');
#menu {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="myAccount_wrap">
  <div id="myAccount_button" onmouseover="$('#menu').show()" onmouseout="$('#menu').hide()">
     my account
  </div>
</div>
<div id="menu">
a<BR/>
c<BR/>
d<BR/>
e<BR/>
</div>

Related


How can I hover over an element and then click using Cypress

Emirhan Rose: I would like to hover over the "My Account" button and click the "Login" button to open the popup. I have tried the code below but it didn't work. Does anyone know a way to handle this situation? thanks, Cypress.Commands.add('loginol', (email, p

How to hover over a div using the <i> element

Mailer I think I'm trying to do a very simple effect. I have a menu with 4 icons and I want the description to slide right on hover. I'm not sure I can do this with CSS because the div is after the closing tag of the first div, and I tried it +but nothing happ

How to hover over a div using the <i> element

Mailer I think I'm trying to do a very simple effect. I have a menu with 4 icons and I want the description to slide right on hover. I'm not sure I can do this with CSS because the div is after the closing tag of the first div, and I tried it +but nothing happ

Hover over button using Cypress

Asoni I'm trying to hover over a button in Cypress, and for that, I've tried using a trigger('mouseover'), but it doesn't work for me. Any suggestions? it('hovering over button', () => { cy.visit("http://www.qaclickacademy.com/practice.php"); cy.get('#mouseh

How to hover over a div using the <i> element

Mailer I think I'm trying to do a very simple effect. I have a menu with 4 icons and I want the description to slide right on hover. I'm not sure I can do this with CSS because the div is after the closing tag of the first div, and I tried it +but nothing happ

Hover over button using Cypress

Asoni I'm trying to hover over a button in Cypress, and for that, I've tried using a trigger('mouseover'), but it doesn't work for me. Any suggestions? it('hovering over button', () => { cy.visit("http://www.qaclickacademy.com/practice.php"); cy.get('#mouseh

How can I hover over an element and then click using Cypress

Emirhan Rose: I would like to hover over the "My Account" button and click the "Login" button to open the popup. I have tried the code below but it didn't work. Does anyone know a way to handle this situation? thanks, Cypress.Commands.add('loginol', (email, p

Hover over button using Cypress

Asoni I'm trying to hover over a button in Cypress, for that I've tried using a trigger('mouseover') but it doesn't work for me. Any suggestions? it('hovering over button', () => { cy.visit("http://www.qaclickacademy.com/practice.php"); cy.get('#mousehover')

How to hover over a div using the <i> element

Mailer I think I'm trying to do a very simple effect. I have a menu with 4 icons and I want the description to slide right on hover. I'm not sure I can do this with CSS because the div is after the closing tag of the first div, and I tried it +but nothing happ

Hover over button using Cypress

Asoni I'm trying to hover over a button in Cypress, and for that, I've tried using a trigger('mouseover'), but it doesn't work for me. Any suggestions? it('hovering over button', () => { cy.visit("http://www.qaclickacademy.com/practice.php"); cy.get('#mouseh

Hover over button using Cypress

Asoni I'm trying to hover over a button in Cypress, and for that, I've tried using a trigger('mouseover'), but it doesn't work for me. Any suggestions? it('hovering over button', () => { cy.visit("http://www.qaclickacademy.com/practice.php"); cy.get('#mouseh