Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving mouse (move_to) in ruby Selenium

I`m trying to emulate mouse movement with Selenium WebDriver 2.4 in Ruby

Should I see the mouse moving on my screen if I run the test? I'm confused.

I have tried many different ways Sample code:

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'http://www.google.com'
element = driver.find_element(:id, 'gbqfba')

then I've tried

driver.action.move_to(element).perform
driver.mouse.move_to(element)

And also Watir's hover method.

Best way I've found so far is Watir's fire_event 'onmouseover' But still not moving the mouse :)

After searching on SO and elsewhere, I can't seem to get anything to work for moving the mouse in WebDriver.

Whass going on? Is it possible to actually move the mouse cursor on screen (when the webdriver browser window is in view)

like image 335
cannotcompute Avatar asked Mar 20 '14 18:03

cannotcompute


People also ask

How do you move a mouse to a element in Action class?

We can move mouse pointer to a specific location or element in Selenium webdriver(C#) using the Actions class. We have to first create an object of this class. Next to move an element we have to apply the MoveToElement method and pass the element locator as a parameter to this method.

What are the mouse movements in Action class?

dragAndDropBy(source, xOffset, yOffset): Click-and-hold at the location of the source element, moves by a given offset. moveByOffset(x-offset, y-offset): Moves the mouse from its current position (or 0,0) by the given offset. moveToElement(toElement): Moves the mouse to the middle of the element.


1 Answers

The answer is No You will not visually see your mouse move. Selenium interacts with the page internally which means it will not use your desktop mouse.

If you are afraid it's not working, then maybe you are operating with the wrong element because driver.action.move_to(element).perform is valid.

like image 138
ddavison Avatar answered Oct 10 '22 07:10

ddavison