Mouse hover using WebDriver

21,013 views
Skip to first unread message

valerio

unread,
Jul 26, 2011, 9:57:09 AM7/26/11
to Selenium Users
Hi,
In my test script I have to hover over an element which as a result
gets highlighted.
Basically, it gets highlighted on 'mouseover' event being sent and
returns to its normal style on sending 'mouseout'.

Using mouseOver() old Selenium API, it was possible to issue only
'mouseover' event and the element I am testing would remain updated.

Using moveToElement() or mouseMove() in WebDriver, it seems as if
these methods are implemented differently as they send a 'mouseover'
and immediately after a 'mouseout' event. So, I see the element on my
page flashing.

Is there a way to obtain the same behaviour using WebDriver?

Thanks,
Valerio

Yuping Zhong

unread,
Jul 26, 2011, 11:21:04 PM7/26/11
to seleniu...@googlegroups.com
I also meet the same issue when use the Webdriver. 

Any expert can give the clue how to use mouse_over on Webdriver???

Thanks!


--
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.


robbie....@nokia.com

unread,
Jul 27, 2011, 3:59:41 AM7/27/11
to seleniu...@googlegroups.com
I've observed this in FF, but it seems to persist in IE & Chrome

Thanks,
Valerio

--

Jayakumar C

unread,
Jul 27, 2011, 10:44:09 AM7/27/11
to seleniu...@googlegroups.com
@ Valerio,

You may try to execute some JS to fire the hover event.
If your page has JQuery, it would be something like,

((JavascriptExecutor)driver).executeScript("$('div#elementid').hover();");

or

((JavascriptExecutor)driver).executeScript("$('div#elementid').mouseenter();");



--
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.




--
Jayakumar

Mark Collin

unread,
Jul 27, 2011, 11:21:31 AM7/27/11
to seleniu...@googlegroups.com

You have a couple of options.

 

Use the Actions implementation:

 

WebElement myElement =driver.findElement(By.xpath("//foo"));

Actions builder = new Actions(driver);

builder.moveToElement(myElement).build().perform();

 

Dive into the guts of selenium and hjack the Mouse implementation instead of using it via the Actions implementation:

 

Locatable hoverItem = (Locatable) driver.findElement(By.xpath("//foo"));

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

mouse.mouseMove(hoverItem.getCoordinates());


-- 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

valerio

unread,
Jul 27, 2011, 2:40:17 PM7/27/11
to Selenium Users
@Mark
I have already tried that. Sorry for not pasting code. I think the API
currenlty does not provide for that.
@Jayakumar
Thanks I'll try that.

On Jul 27, 5:21 pm, "Mark Collin" <m...@ardescosolutions.com> wrote:
> You have a couple of options.
>
> Use the Actions implementation:
>
> WebElement myElement =driver.findElement(By.xpath("//foo"));
>
> Actions builder = new Actions(driver);
>
> builder.moveToElement(myElement).build().perform();
>
> Dive into the guts of selenium and hjack the Mouse implementation instead of
> using it via the Actions implementation:
>
> Locatable hoverItem = (Locatable) driver.findElement(By.xpath("//foo"));
>
> Mouse mouse = ((HasInputDevices) driver).getMouse();
>
> mouse.mouseMove(hoverItem.getCoordinates());
>
> From: seleniu...@googlegroups.com
> [mailto:seleniu...@googlegroups.com] On Behalf Of Yuping Zhong
> Sent: 27 July 2011 04:21
> To: seleniu...@googlegroups.com
> Subject: Re: [selenium-users] Mouse hover using WebDriver
>
> I also meet the same issue when use the Webdriver.
>
> Any expert can give the clue how to use mouse_over on Webdriver???
>
> Thanks!
>
> On Tue, Jul 26, 2011 at 9:57 PM, valerio <valer...@gmail.com> wrote:
>
> Hi,
> In my test script I have to hover over an element which as a result
> gets highlighted.
> Basically, it gets highlighted on 'mouseover' event being sent and
> returns to its normal style on sending 'mouseout'.
>
> Using  mouseOver() old Selenium API, it was possible to issue only
> 'mouseover' event and the element I am testing would remain updated.
>
> Using moveToElement() or mouseMove() in WebDriver, it seems as if
> these methods are implemented differently as they send a 'mouseover'
> and immediately after a 'mouseout' event. So, I see the element on my
> page flashing.
>
> Is there a way to obtain the same behaviour using WebDriver?
>
> Thanks,
> Valerio
>
> --
> 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
> <mailto:selenium-users%2Bunsu...@googlegroups.com> .
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> 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 athttp://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 postmas...@ardescosolutions.com

Jaie Wilson

unread,
Jul 28, 2011, 10:06:06 AM7/28/11
to seleniu...@googlegroups.com
Hi Valerio,

It depends on what OS and browser you are using. Can you confirm the Browser/OS you are using?

Currently Firefox on mac does not handle native events and as such I don't think the mouseout is working correctly for Firefox, maybe similar on other operating systems too.
Chrome and html unit seem to handle this fine if the mouseover and mouseout are via javascript. The only browser I've tested on a Mac that handles the pseudo class :hover seems to be chrome at the moment.

I've written a helper utility MouseEvents which has a hover and mouseout method. For mouseout when running firefox I just fire a mouseout event on the element using the javascript executor, but for everything else it uses the Actions class to move the mouse to the element you want to move it to mouseout of and then uses another move to element where the second element is the driver.findElement(By.tagname("head")). So far my testing has been working for this. The reason for the second move to element instead of the move mouse by offset is that HTML unit driver doesn't currently support moving the mouse by cords via the actions class.

Mouse over is pretty straight forward as the Actions.moveToElement seems to do the trick (except for css :hover this requires native event support in FF).

I will post a link tomorrow to my implementation if you want more details.

Cheers,
Jaie


bruce

unread,
Aug 3, 2011, 4:14:12 AM8/3/11
to Selenium Users
The following method does not work. I use Selenium 2.3 java FF3.6

Actions builder = new Actions(driver);

WebElement we = driver.findElement(By.xpath("//
div[contains(@style,'visible')]//a[text()='Reports']"));
builder.moveToElement(we).build().perform();




On 7月27日, 下午11时21分, "Mark Collin" <m...@ardescosolutions.com> wrote:
> You have a couple of options.
>
> Use the Actions implementation:
>
> WebElement myElement =driver.findElement(By.xpath("//foo"));
>
> Actions builder = new Actions(driver);
>
> builder.moveToElement(myElement).build().perform();
>
> Dive into the guts of selenium and hjack the Mouse implementation instead of
> using it via the Actions implementation:
>
> Locatable hoverItem = (Locatable) driver.findElement(By.xpath("//foo"));
>
> Mouse mouse = ((HasInputDevices) driver).getMouse();
>
> mouse.mouseMove(hoverItem.getCoordinates());
>
> From: seleniu...@googlegroups.com
> [mailto:seleniu...@googlegroups.com] On Behalf Of Yuping Zhong
> Sent: 27 July 2011 04:21
> To: seleniu...@googlegroups.com
> Subject: Re: [selenium-users] Mouse hover using WebDriver
>
> I also meet the same issue when use the Webdriver.
>
> Any expert can give the clue how to use mouse_over on Webdriver???
>
> Thanks!
>
> On Tue, Jul 26, 2011 at 9:57 PM, valerio <valer...@gmail.com> wrote:
>
> Hi,
> In my test script I have to hover over an element which as a result
> gets highlighted.
> Basically, it gets highlighted on 'mouseover' event being sent and
> returns to its normal style on sending 'mouseout'.
>
> Using  mouseOver() old Selenium API, it was possible to issue only
> 'mouseover' event and the element I am testing would remain updated.
>
> Using moveToElement() or mouseMove() in WebDriver, it seems as if
> these methods are implemented differently as they send a 'mouseover'
> and immediately after a 'mouseout' event. So, I see the element on my
> page flashing.
>
> Is there a way to obtain the same behaviour using WebDriver?
>
> Thanks,
> Valerio
>
> --
> 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
> <mailto:selenium-users%2Bunsu...@googlegroups.com> .
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> 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 athttp://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 postmas...@ardescosolutions.com

valerio@TomTom

unread,
Aug 3, 2011, 10:38:51 AM8/3/11
to Selenium Users
Hi Jaie,
thanks for your help. I have done quite some experiments.
Just for the sake of clarity I am using RemoteWebDriver.

These are my observations:
Firefox 4 on WinXP
moveToElement: NOK. mouseover is sent to the element. Afterwards
mouseout (or some other...) is also sent resulting in a non-persistent
hovering behaviour.
mouseMove: NOK.same as above.

Explorer 7
moveToElement: NOK. Same as WinXp.
mouseMove: NOK. Same as WinXp.

Chrome 12 on WinXP
moveToElement: OK. Noticed when hovering on another element, the first
element receives an event that makes hovering end. This is different
from the behaviour of Selenium mouseOver() method, which I prefer.
mouseMove: OK. Same observation as above.

Firefox 4 on Leopard
moveToElement: OK.
mouseMove: OK.

Chrome 13 on Leopard
moveToElement: OK
mouseMove: OK

urbanblock

unread,
Sep 5, 2011, 7:32:15 PM9/5/11
to seleniu...@googlegroups.com
Hi
Did you find any answer to this? I have the same problem with moveToElement triggering mouseout immediately after mouseover. 

I am using  FF3.6 and 4 on Windows XP using selenium-server-standalone-2.5.0.jar.

Code is 
Actions builder = new Actions(driver);    
builder.moveToElement(element).build().perform();

I have also tried MoveToOffsetAction - with same issue.

Regards,
Dylan

robbie....@nokia.com

unread,
Sep 6, 2011, 3:56:06 AM9/6/11
to seleniu...@googlegroups.com

From my experience this problem is restricted to Firefox. Have you tried running the tests on IE , Chrome or Opera?

--

You received this message because you are subscribed to the Google Groups "Selenium Users" group.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/xEECK9ThkQcJ.

Dylan Hazlehurst

unread,
Sep 6, 2011, 4:56:09 AM9/6/11
to seleniu...@googlegroups.com
Hi
Thanks for the tip - is working fine for me in IE and Chrome. Guess
I'll have to avoid Firefox.

Cheers,
Dylan

robbie....@nokia.com

unread,
Sep 6, 2011, 5:39:52 AM9/6/11
to seleniu...@googlegroups.com
I heard a rumour that it was fixed in the latest version of Selenium Webdriver.

Also, you could cheat in Firefox by executing the javascript directly. This is not a valid a test but would allow you to test any functionality after the mouseover.

Duy Nguyễn Phúc

unread,
Sep 6, 2011, 4:20:52 AM9/6/11
to seleniu...@googlegroups.com
Hi!

You should use as:

    Actions builder = new Actions(driver);
    Action drapAndDrop = builder.clickAndHold(element)
                                              .moveToElement(other element)
                                              .release(other element)
                                              .build();
              drapAndDrop.perform();

Regards,
Duy Nguyen Phuc

Duy Nguyễn Phúc

unread,
Sep 6, 2011, 4:19:18 AM9/6/11
to Selenium Users

Duy Nguyễn Phúc

unread,
Sep 6, 2011, 4:19:46 AM9/6/11
to Selenium Users
Hi!
You should use as:

Actions builder = new Actions(driver);

Duy Nguyễn Phúc

unread,
Sep 6, 2011, 4:22:43 AM9/6/11
to Selenium Users
Hi!
You should use as:

Actions builder = new Actions(driver);

annie

unread,
Feb 25, 2012, 12:51:07 PM2/25/12
to seleniu...@googlegroups.com
Hi 

Did anyone find the workaround for this issue ?
I am facing the same issue when i need to move the mouse to an object such that some hidden div will be displayed.

Thanks

mathew kuruvila

unread,
Mar 9, 2012, 9:48:44 AM3/9/12
to seleniu...@googlegroups.com
Somebody above said it's working in IE, if so is it working in IE7/8 - XP. And which version of selenium?

Peter Gale

unread,
Jul 4, 2012, 4:22:59 PM7/4/12
to seleniu...@googlegroups.com
>Is it possible to stimulate hovering cursor over an element ...
Yes ... this was answered in another similar thread in the last day or so.

> ...in order to get tooltip?
I don't think Selenium Webdriver can read the displayed tooltip as such, only whatever attribute of the element stores the text, which should be the same thing.


Date: Wed, 4 Jul 2012 10:32:48 -0700
From: michal.n...@gmail.com

To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: Mouse hover using WebDriver

Is it possible to stimulate hovering cursor over an element in order to get tooltip?
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/qb0pYTgXKFwJ.

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-US.

Alex

unread,
Oct 8, 2012, 5:01:08 AM10/8/12
to seleniu...@googlegroups.com
as other have said use the actions. one tip i can give you is to not use single actions. i tried doing a hover that reveals a menu and then click something in that menu and it ran like shit in IE and barely in FF but after i did chain actions instead of mutiple independent ones it worked in all browsers flawlessly.

Marilyn C. Cole

unread,
Aug 7, 2013, 2:53:07 PM8/7/13
to seleniu...@googlegroups.com
I also have not been able to get a hover event to successfully trigger with FirefoxDriver.  The web app tooltip was created with extJS, which may be resulting in strange behavior, because the standard Actions.moveToElement(helpIcon).perform() is not triggering the tooltip popup text.  I also tried using the JSExecutor like so:

String js = "var evObj = document.createEvent('MouseEvents');" +
                    "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" +
                    "arguments[0].dispatchEvent(evObj);";
((JavascriptExecutor)driver).executeScript(js, helpIcon);

I don't have access to jQuery here.  I believe the above should work, and it doesn't result in any error, but it also doesn't pop the help text up.  Manually, it's easy -- mousing over or hovering over the helpIcon element makes the help info window come up immediately.

Any other ideas?

Thanks,
Marilyn


On Thursday, May 9, 2013 10:29:03 AM UTC-4, Nidhi Paroha wrote:
@Alex - Can you please share the action chains that you used to solve this issue?  The mouse out feature does not work for me. I am using firefox on mac. I tried few different options like hover over any other element on the page, move to offset etc. but none of those seem to be working. :(

manvendra kumar mishra

unread,
Oct 28, 2014, 8:52:24 AM10/28/14
to seleniu...@googlegroups.com
Hi,


did u find any solution,
I am facing the same problem.
it work fine if drop down menu created using javascript, bu
when i tried to hover on drop down menu created using css, it doesn't work. i mean drop down list doesn't open.


Any help will be appreciated.


Thanks & Regards
Manvendra kumar Mishra

Krishna Reddy Gtpv

unread,
Oct 29, 2014, 6:41:51 AM10/29/14
to seleniu...@googlegroups.com
Use following code

Actions a = new Actions(driver);
a.movetoelement(driver.findElement(By.xpath("").perform();

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.



--
Thanks & Regards
Krishna Reddy Gtpv | Software Engineer | Anblicks Solutions Pvt Ltd
Blog : www.gtpvkr.in  | E Id  : gtp...@gmail.com | Ph : +91 - 9494585126

   




manvendra kumar mishra

unread,
Oct 30, 2014, 2:33:28 AM10/30/14
to seleniu...@googlegroups.com
Hi,

I have already tried that with no success.. :( 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/927b8a78-5d79-4989-9e9f-bb8a7d43387c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Manvendra Kumar MIshra
B.TECH Bioinformatics
Dr.D.Y.Patil University

CH!NN@ K

unread,
Oct 30, 2014, 5:19:14 AM10/30/14
to seleniu...@googlegroups.com
hi Mishra, when your want to mouse over(drop down) then you can use  "SIKULI" in selenium. It is working fine on mouse over programs.
This below link is one of example of mouse over program : http://techlearn.in/content/mouse-over-program-sikuli

---
Thanks & Regards,
Purushotham Karimbedu,
Web Developer and QA Engineer,
Personal Website : http://techlearn.in
Phone no :9000109120.

Reply all
Reply to author
Forward
0 new messages