11

Using selenium-rc and the java client, I want to test a menu which opens when the user moves the mouse over it. It closes when the mouse leaves the menu. This is done using :hover css, without any javascript.

In selenium, there are many methods for mouse actions, but none of them seems to trigger any css :hover style to be used.

Google shows that I am not alone with this problem, but there has not be a solution. Some folks comment that you had to add some javascript code; however, in selenium rc, I don't think that I even have a proper place for user-contributed additional javascript code.

My wish would be the following code to work, given that a div#navi_settings contained the menu which contains the - normally invisible - a element:

selenium.mouseHover("css=div#navi_settings");
assertTrue(selenium.isVisible("//a[contains(text(), 'Text on link')]"));

Unfortunately, the method moveHover() does not yet exist.

Moritz Both
  • 1,598
  • 1
  • 13
  • 21

2 Answers2

1

I couldn't find a way to do this using the Selenium interface. However, since I am using Selenium 2, I can use the WebDriver API, as per http://groups.google.com/group/selenium-developers/msg/8210537dde07155f?pli=1

In your case, something like this may work, if you can upgrade to Selenium 2:

WebDriver webDriver; 
...
((RenderedWebElement) webDriver.findElement(By.cssSelector("div#navi_settings"))).hover();
Rob
  • 982
  • 8
  • 14
  • 1
    This works on platforms that have Selenium native events support (Linux and Windows). On Mac, you are out of luck currently: https://groups.google.com/group/webdriver/browse_thread/thread/c08444af61cc2898 – John Dec 22 '10 at 19:12
-1

The mouseOver method will activate a :hover pseudoclass.

techpeace
  • 2,606
  • 1
  • 22
  • 21
  • 1
    Since when? In selenium server v2.0 [a2], with Core v2.0 [a2], this did not work, at least with firefox 3.5. – Moritz Both Aug 19 '10 at 15:18
  • Then use some javascript to make the menu visible when you need to click one of its elements. That's what I ended up doing, and it worked fine. Or try asking your question on the Selenium mailing list. – techpeace Aug 23 '10 at 15:39
  • mailing list: ok, your point, but the menu visibility is css driven which is working well. Testing clicks on menu items is not the problem. I am testing the *visibility itself* when the user hovers over the menu. Changing the application to use javascript instead of css is out of the question. – Moritz Both Aug 26 '10 at 10:45