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.
The first step here would be to locate the main menu (AKA parent menu). Once that is done, the second step is to locate the desired element (child element) from the available options in the sub-menu. The final step would be to click on that child element.
We can get the tooltip text in Selenium webdriver with help of the method - getAttribute. The attribute title should be passed as a parameter to this method. This technique is only applicable if the element has a title attribute. The tooltip text is the one which gets displayed on hovering the mouse over the element.
In computing, a mouseover , mouse hover or hover box is a graphical control element that is activated when the user moves or hovers the pointer over a trigger area, usually with a mouse, but also possible with a digital pen. Mouseover control elements are common in web browsers.
Both xOffset and yOffset represent the relative pixel distance (integer) with which to scroll. For xOffset , positive value means to scroll right, and negative value means to scroll left. For yOffset , positive value means to scroll downward, and negative value means to scroll upward.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With