How to hover over an element in Selenium Ruby?

Does anyone know how to hover over an element in Selenium Ruby Webdriver?

My code looks like this:

el = driver.find_element(:css => "#foo") driver.move_to el # How do I trigger a mouseover event on this element? 

I am using selenium-webdriver gem with Firefox on 32-bit Linux.

+6
source share
5 answers

Turns off the answer:

 driver.move_to(el).perform 

I forgot .perform .

+3
source

I used driver.action.move_to(el).perform , which is slightly different from the other answers, so I thought I would include it for completeness.

+5
source

This works for me:

 driver.mouse.move_to el 
+3
source

You need to use the Selenium Action Builder to access more complex actions, such as freezing (as the seanny123 answer demonstrates).

In addition, if you are working with a hang, you will have to dynamically wait for it to appear before you perform the next action (for example, using an explicit wait).

I put together an example on how to do this - you can see the full entry here .

+1
source

To hover an element:

 driver.action.move_to(element).perform # eg driver.action.move_to(driver.find_element(css: 'a')).perform 

To hover an item in a specific place:

 driver.action.move_to(element, mouse_x, mouse_y).perform # eg driver.action.move_to(driver.find_element(css: 'a'), 100, 100).perform 
+1
source

Source: https://habr.com/ru/post/896368/


All Articles