Webdriver: how to use mouseDown/mouseUp/mouseMove on an element

9,139 views
Skip to first unread message

Ahmed EL AMINE

unread,
Nov 9, 2011, 4:46:18 AM11/9/11
to Selenium Users
i'm looking for the right way to do some mouse actions on web
elements. I just discovered this previous post:
http://groups.google.com/group/selenium-users/browse_thread/thread/20bd00e77c107fe3
but no response was posted on it.

it would be very nice if some one shows the right method :)

Mark Collin

unread,
Nov 10, 2011, 1:36:52 AM11/10/11
to seleniu...@googlegroups.com
On way would be to do something like this (assuming your WebDriver object is
called driver):

Mouse mouse = ((HasInputDevices) driver).getMouse();
WebElement myElement = driver.findElement(By.id("foo"));

mouse.mouseDown((Coordinates) myElement.getLocation());
mouse.mouseUp((Coordinates) myElement.getLocation());

I'm assuming it will let you cast a point object into a coordinates object,
I haven't tried the above. I'm guessing that the mouse interaction isn't
fully fleshed out yet, a lot of the context xlixk stuff is not available on
the Actions object and there are some bits missing from the Mouse object as
well e.g. right mouse down and right mouse up. Then again you don't
normally need to hold down your right mouse button when using a website...

--
You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to
selenium-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/selenium-users?hl=en.


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Fernando Cervera

unread,
Nov 9, 2011, 4:59:41 PM11/9/11
to seleniu...@googlegroups.com

Mark Collin

unread,
Nov 10, 2011, 9:55:15 AM11/10/11
to seleniu...@googlegroups.com

The advanced user interaction API used the mouse and keyboard objects and is really the correct way to deal with it.  I’ve got carried away and gone down too deep again ;P)

Carmen Rosa G. Us

unread,
Feb 4, 2014, 3:59:26 AM2/4/14
to seleniu...@googlegroups.com
This one worked for me for 'on mouse up'.

     Locatable hoverItem = (Locatable) findElement(by);

    Mouse mouse = ((HasInputDevices) driver).getMouse();

Reply all
Reply to author
Forward
0 new messages