Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Hover with native events on Windows is not persisted #2067

Closed
lukeis opened this issue Mar 2, 2016 · 98 comments
Closed

Hover with native events on Windows is not persisted #2067

lukeis opened this issue Mar 2, 2016 · 98 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 2067

I have noticed that in Firefox (I am using 5), the moveToElement 
action is not persisted.  By "persisted", I mean that I can see the 
mouse over event triggered but then immediately stop.  When using 
Chrome & Opera, the "hover" continues until the next selenium action. 
This means that with FF, I cannot assert that the "hover" has 
triggered the correct behaviour because the attributes I have to check 
have changed back by the time I assert on them! As I said, Chrome & 
Opera work fine. 

Selenium Webdriver 2.0.0 (Java)
O/S Windows 7 & Windows XP
Firefox 5

Reported by wareham.robbie on 2011-07-18 08:16:28

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Is your real mouse cursor over the Firefox window? If so, forcing the real cursor not
to be over the real window may help.

Reported by dawagner on 2011-07-18 09:52:31

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

No, I can confirm that my real mouse cursor is not over the firefox window

Reported by wareham.robbie on 2011-07-26 13:59:14

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I think this because Firefox Driver triggers a Hover event where as mouseover would
persist

Reported by wareham.robbie on 2011-08-15 07:36:40

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Can this be fixed and kindly be prioritised to HIGH as hovering is quite common on web2.0
testing and not having this fixed is awful.

Reported by raghu.alapati1 on 2011-09-01 04:05:11

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I also face the same issue. But it's not only with firefox, it's problem with IE browser
too. I checked in FF 3.6, FF6, IE8 [and all these browsers problem persists]. However
in chrome it worked perfectly. Also sometimes even mouse over using [movetoelement]
itself is not getting performed on FF. Sometimes we are facing mouseover (element persistent)
issue, sometimes mouseover itself doesn't happen. The same test case which works once
doesn't work other time is really frustrating.
Note: I tried using Selenium 2.5.0, 2.6.0 & 2.7.0 (but no luck)

Can you please fix this issue asap.

Reported by pavithz on 2011-10-04 10:23:21

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

yes, please fix this.  This only works on Chrome and not the other browsers :(

Reported by glory.leung on 2011-10-06 16:54:15

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Marked!~

Reported by binken.zou on 2011-10-09 11:02:02

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by barancev on 2011-10-13 06:31:35

  • Labels added: Component-WebDriver, Browser-Firefox

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 2636 has been merged into this issue.

Reported by barancev on 2011-10-13 07:20:51

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 2193 has been merged into this issue.

Reported by barancev on 2011-10-13 07:21:34

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

First, it'd help to get a sample HTML demonstrating the problem - The internal hover
tests (using the WebDriver API) work well.
Second, there'll be a change to the moveToElement in the upcoming  release (2.10?).
I'd suggest trying again after this release (a sample page will yield a faster response,
of course). 

Reported by eran.mes on 2011-10-18 16:37:26

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

            var driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/HoverMenu/HoverMenu.aspx");
 var action = new OpenQA.Selenium.Interactions.Actions(driver);
            action.MoveToElement(driver.FindElement(By.Id("ctl00_SampleContent_GridView1_ctl09_Label1"))).Perform();
            driver.FindElement(By.Id("ctl00_SampleContent_GridView1_ctl09_Label1")).Click();

Reported by binken.zou on 2011-10-18 18:39:59

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am writing some code using the latest 2.8.0 version. 

Reported by binken.zou on 2011-10-18 18:40:30

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Sorry for type the wrong ID in the line five should be "ctl00_SampleContent_GridView1_ctl09_LinkButton1"

Reported by binken.zou on 2011-10-18 18:43:04

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

 var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("file:///C:/Users/binken/Desktop/SampleDetails.htm");
var action = new OpenQA.Selenium.Interactions.Actions(driver);
var element = driver.FindElement(By.Id("linkSampleFavourites"));
action.MoveToElement(element).Perform();
driver.FindElement(By.Id("favRemoveLink140075")).Click();


The code above should display a popup window with OK and Cancel
But it's not

Reported by binken.zou on 2011-10-18 19:28:43


- _Attachment: [demo.zip](https://storage.googleapis.com/google-code-attachments/selenium/issue-2067/comment-15/demo.zip)_

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Using 2.11.0 moveToElement still does not hover on firefox (works on Chrome).  Any idea
when this will be resolved?

Reported by damien.hollis on 2011-11-02 02:59:00

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

An html snippet and client code would help answering this question.

Reported by eran.mes on 2011-11-02 04:26:11

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Hi, eran, I have upload the demo.zip file , you may have a look at this!

Reported by binken.zou on 2011-11-02 08:30:00

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I DO confirm that the script doesn't work. I am using WebDriver 2.9. when executing
the script with Firefox browser, the item is hover quickly. so that, the following
actions failed. 
My script is 
Actions builder = new Actions(driver);
builder.MoveToElement(myElement).Perform();   
anotherElement.Click() // failed of  course

Reported by tmsnhien on 2011-11-02 12:03:51

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Yeaa this is realy a show stopper for me as well.Before reading this article i tried
many option to click a submenu item in IE browser but no help .

My code looks like .

WebElement menu= driver.findElement(By.id("arr_ID_NEWLOANONLINE"));//this is the main
toolbar menu//
menu.click();

WebElement wc= driver.findElement(By.xpath("table[@class='mnuSubMenu_Base']/tbody/tr[1]/td[2]"));
//this is submenu first item//

new Actions(driver).moveToElement(wc).click.perform() //not clicking anywhere but script
execution moved forward.//

Please resolve this if its really a issue with IE/webdriver compatibility.









Reported by naveencha on 2011-11-09 12:13:58

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

There are known issues with moveToElement on IE, and there are no good workarounds that
can be applied within the WebDriver code. For IE, you need to make sure that the physical
mouse cursor is not within the boundaries of the IE browser window for hovering to
work. However, let's try to restrict the comments of this issue to Firefox only, since
the IE issue is already known.

Reported by james.h.evans.jr on 2011-11-09 12:56:39

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Correct me if I'm wrong, but I believe that by injecting javascript, you are essentially
using a form of the non-native approach because you are using the browser to register
the click. Alternatively, the native approach employs O/S level commands to register
the click.  

In my opinion, there is much to be said for keeping native events turned on, and only
using the javascript injection method as a course of action when native events aren't
cutting it (because of a bug, because they haven't been implemented for the browser,
because of the way the site is constructed, etc). Seems like there are less trade-offs.


Brian

Reported by x.bgoad@reverbnation.com on 2012-07-26 17:55:49

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

** This is not relegated to clicks only, I was just using it as an example, but includes
any mouse interactions such as mouse overs, as this Issue implies.

Brian

Reported by x.bgoad@reverbnation.com on 2012-07-26 17:58:05

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Understandable to use native events where possible. This is just an idealistic thought:
but it would be nice if there's a simple approach where if native events somehow don't
work, they'll fail with exception. Then user can catch it and use javascript injected
workaround.

So in this mouse hover example, if cursor is outside browser window, or it just doesn't
take affect somehow, it will throw exception, so we now have catch code that will use
the workaround. But I assume that's not possible in most cases. 

So it is just to always use native events and then when your test fails because the
native event approach didn't work, and you tried everything and it just doesn't work,
then you switch your code to use javascript injected method. No nice try/catch method,
just plain old debugging when test fails from native event related issue and you have
to look into the issue.

Reported by mangaroo on 2012-07-26 18:05:40

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

In reply to comment #76 - I experience the exact opposite behavior.  In order for the
hover to work in Firefox, I need to have the real mouse cursor outside of the browser
window.

Maybe I've written the wrong code? I've tried a few variations, and they are listed
below (c#):

#1)
var clickMainNav = new Actions(_selenium);
clickMainNav.Click(mainNavElement);
IAction hover = clickMainNav.Build();
hover.Perform();

#2)
var clickMainNav = new Actions(_selenium);
clickMainNav.MoveToElement(mainNavElement);
IAction hover = clickMainNav.Build();
hover.Perform();

With option #1 - if the mouse is outside of the window - the menu dropDown that appears
upon hover remains displayed and I can continue to click the sub-menu item that I then
need to navigate to.

With option #2 - if the mouse is outside of the window - the menu dropDown that appears
upon hover just blinks real quick and then disappears.

Either with option #1 or #2 - if the mouse is inside of the window - the menu dropDown
never even appears.  The only thing I see happening is the mainNavElement get highlighted
for a second (as if it was about to execute the hover).


Below is my Firefox profile code.  I've tried the above 2 options with both EnableNativeEvents
= true and false.  I get same behavior described above either way.

if (Config["FFProfile"] == "False")
{
   var defaultProfile = new FirefoxProfile();
   defaultProfile.EnableNativeEvents = true;
   DesiredCapabilities FFCapability = DesiredCapabilities.Firefox();
                                         FFCapability.SetCapability(FirefoxDriver.ProfileCapabilityName,
defaultProfile);

   _selenium = new ScreenShotRemoteWebDriver(new Uri("http://localhost:4444/wd/hub"),
FFCapability);

   _driver = (RemoteWebDriver)_selenium; //These 2 lines of code are to get access
   _mouse = _driver.Mouse;               //to IMouse in different method I use
}

if (Config["FFProfile"] == "True")
{
   var firefoxProfile = new FirefoxProfileManager().GetProfile("FirefoxProfile");
   firefoxProfile.EnableNativeEvents = true;
   DesiredCapabilities FFCapability = DesiredCapabilities.Firefox();
                                        FFCapability.SetCapability(FirefoxDriver.ProfileCapabilityName,
firefoxProfile);

   _selenium = new ScreenShotRemoteWebDriver(new Uri("http://localhost:4444/wd/hub"),
FFCapability);

   _driver = (RemoteWebDriver)_selenium; //These 2 lines of code are to get access
   _mouse = _driver.Mouse;               //to IMouse in different method I use
}


The reason this is an issue for me is because when we run the tests on our CI system,
the real mouse ends up being inside the browser window and then the hover fails.  Any
words of advice would be much appreciated.  Thanks.

Reported by arosszay on 2012-08-16 15:07:33

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Forgot to mention - I'm using Selenium dotnet 2.25.1 and FF14

Reported by arosszay on 2012-08-16 15:10:30

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

After a long struggle, the solution for me on IE was to set
'EnableNativeEvents = false' in the InternetExplorerOptions.

Reported by boaz.farkash on 2012-08-30 08:52:17

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Mark

Reported by Mirror.Zou on 2012-09-07 05:39:39

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I don't understand the meaning of comment #85.

Reported by mangaroo on 2012-09-09 03:38:34

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Comment #79 is right on the money: Native events will usually yield better results unless
there's a bug.

Again, test cases would be very helpful reproducing this. The only one I currently
have is detailed in issue #4535.

Reported by eran.mes on 2012-09-11 12:05:21

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Hi All,

The mouse over functionality is not working as expected in Firefox where as it is working
fine for Chrome and IE9( For IE if we place the mouse out of the execution window its
working fine). I am using the webdriver method moveToElement().

Can any one find the solution please share with.

I am using selenium stand alone server 2.28.0 and latest IE and Chrome drivers. And
my Firefox is 18.0.1

Reported by kumar.sandeep528 on 2013-02-12 09:17:18

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I don't see that 2.28.0 supports FF 18, so native events are probably broken.  Try downgrading
to FF 17 and it will probably work.

Reported by lvskiprof on 2013-02-12 20:02:21

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Does not work for me: Selenium 2.29.0, Python driver (via SST), Firefox 16 on Debian.

Drag works, but the mouseup event handler on the web page is not executed.

Reported by florian.sesser on 2013-02-13 15:48:13

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Agree with #66. My generation observation is that for FF on Windows, the physical mouse
needs to be within the window bounds for hover to not be 'undone'

a workaround that is silly for most cases but perhaps works fine for some cases is
to click on the body element right before the hover:

el = findElement(By.cssSelector(".myelem")); // element to hover on
findElement(By.cssSelector("body").click(); // without this, when mouse is not over
window, it fails to hover
new Actions(driver).moveToElement(el).build().perform(); // works only with line 2
present

Reported by binod80 on 2013-04-04 20:20:00

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

If you are still suffering this we 'resolved' this on our Grid by using a Windows script
that moves the mouse to a set location (I can't remember, about (20,20) or thereabouts).
It checks and moves on a timed schedule. 

If somebody logs into the machine and fiddles with it then it will 'reset' itself.
This has been solid for us for about 9 months now. We considered building it into Grid
to trigger it from Grid events like browser start but as it is it's been reliable enough
we no longer felt the need.

Of course this doesn't really work if you're running locally, or testing on IE  :)

Reported by campbell.zac on 2013-04-04 21:22:53

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

For all browsers,
action = new Action(driver);
action.moveToElement(parentItem).build.perform();

WebDriverWait wdw = new WebDriverWait(driver,100);
wdw.until(ExpectedConditions.elementToBeClickable(by));
driver.findElement(by).click();

For IE
ieCapabilities.setCapability("requireWindowFocus", true);
ieCapabilities.setCapability("enablePersistentHover", false);
For Chrome
Sleep(5000) before hovering and after hovering...

Reported by tmsnhien on 2013-05-09 12:29:33

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@tmsnhien comment#93
Waiting 5sec before and after? That's a bad joke.

Reported by garfieldklonklon on 2013-08-27 11:27:18

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am pretty confused about this. Some pages suggest turning native events on, others
off. When I turn them off drag and drop breaks, when I turn them on hover and click
actions break. I have over 200 tests and this area (simulating mouse events) has been
the biggest headache. I have been reduced to making hidden elements visible using JavaScriptExecutor
for the moment which is not ideal. Are there any Selenium definitive guidelines on
how to get this all to work reliably?

Reported by acarlonvsn on 2013-11-12 05:13:37

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

no visibility of mouse over of comments
 #57 ,  
 #60,
 #64..
even though its succesfull, let me know ifyou are able to execute java script "mouse
over" with visibilty on safari

Reported by sashankgangi on 2013-11-26 11:02:15

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by eran.mes on 2014-10-29 11:02:31

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Hi,
Does anyone know mouse over on safari browser on mac .tried solution #60.it didn't
work. 

Reported by attar.reshma on 2015-02-27 20:38:38

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

#99, there is a specific thread for this Safari issue:
https://code.google.com/p/selenium/issues/detail?id=4136

This defect is closed already.

Reported by cbaldan@daitangroup.com on 2015-03-24 21:55:57

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

#57 worked for me (thank you). This is the python version
  js_script = ''.join(["var elem = document.getElementById('",            
            element_id,                                                     
            "');",                                                              
            "if( document.createEvent) {",                                      
            "var evObj = document.createEvent('MouseEvents');",                 
            "evObj.initEvent( 'mouseover', true, false );",                     
            "elem.dispatchEvent(evObj);",                                       
            "} else if( document.createEventObject ) {",                        
            "elem.fireEvent('onmouseover');",                                   
            "}"])                                                               
        driver.execute_script(js_script)  

Reported by mike@adaptivetherapy.com on 2015-08-04 04:16:25

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Regarding comment 96, what is meant by "visibility"? That one doesn't see the mouse
actually move over or hover over the element of interest? Or that the hover/mouse over
doesn't trigger the hidden element to become visible even though the executed code
does not return failure/exception?

If the latter, javascript code (the mentioned workarounds) tend not to throw exceptions
for these mouse operations. It either works or not. 

Also, the workaround only works for elements hidden using javascript on the web site/application.
If it is hidden by CSS, the workaround doesn't work, and you may have to fiddle with
CSS styling to force it to show up instead, faked mouse events won't trigger it.

If the former, the javascript code to simulate the hover may or may not visually show
mouse action depending on the browser type and speed of the operation. But why would
one care in this case?

Reported by mangaroo on 2015-08-04 04:59:58

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 18:13:16

  • Labels added: Restrict-AddIssueComment-Commit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant