If you have created some client functionality that is triggered when the user moves the mouse over an element, you may run into trouble testing with Selenium’s mouseOver method.

I recently implemented such a feature using jQuery’s hover event handler and pulled my hair out trying to test the functionality with Selenium. I went down a complete rat hole trying trigger the event within selenium using the getEval method and passing in custom javascript code. What a nightmare. That is, until I really sat down and thought about it.

Remember that Selenium doesn’t actually control the pointer in the browser but drives the browser through javascript. Therefore, unlike a true mouse event that may trigger a number of events, Selenium’s mouseOver just triggers mouseover on the element. Now, if you have used jQuery’s hover then you are binding your functionality to mouseenter and mouseleave not mouseover and mouseout.

Therefore, if you wish to test with Selenium, do not use jQuery’s hover method and bind your functionality to mouseover and mouseout.

Note that many older browsers do not support mouseenter and mouseleave as this was introduced by Microsoft and was not immediately adopted by the others. There is also a big difference in their behaviour and propagation in the event model. mouseover and mouseout bubble up whereas mouseenter and mouseleave do not bubble up.

  3 Responses to “mouseOver events in Selenium and jQuery hover”

  1. [...] mouseOver events in Selenium and jQuery hover provides a warning around JQuery’s hover binding. Though I think fire_event(‘locator’, ‘hover’) might have also worked. [...]

  2. I had the same problem in IE. Now it works. Thanks!

  3. While in IDE both mouseOver and mouseOut are working, they are not working when I am running my code.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

© 2015 rootsmith blog Suffusion theme by Sayontan Sinha