how to find the hidden menu item and click it

1,146 views
Skip to first unread message

hairinwind

unread,
Dec 4, 2010, 2:23:30 PM12/4/10
to webdriver
Our project has a menu implemented by css hover. When the mouse is on
the first level menu item, the second level menu items will be
displayed. My test need click one second level menu item. But web
driver cannot find it as initially it is hidden.

How to make it?

Thanks!

Simon Stewart

unread,
Dec 5, 2010, 12:59:32 PM12/5/10
to webd...@googlegroups.com
You could try using the Advanced User Interactions APIs, which are
designed for exactly this sort of case:

Action action = new ActionChainsGenerator(driver)
.moveToElement(firstElement)
.click(secondElement)
.build();
action.perform();

Cheers,

Simon

> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>
>

Dreamer

unread,
Dec 6, 2010, 8:24:36 AM12/6/10
to webdriver
Hi I also have that issue. I tried using the RenderedWebElement, but
that did not seem to work, in anaycase that .hover() is only supposed
to work with firefox.
if you know what java script function causes the menu to drop down
then you can execute it drirectly and capture screenshot just to test
that it works.

WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return document.title");

David

Dreamer

unread,
Dec 6, 2010, 9:03:59 AM12/6/10
to webdriver
Hi Simon,

tried that bit of code, but its' complaining about a cast exception.

java.lang.ClassCastException:
org.openqa.selenium.firefox.FirefoxDriver cannot be cast to
org.openqa.selenium.HasInputDevices.

That's to do with the method in the ActionsChaingenerator class

public ActionChainsGenerator moveToElement(WebElement toElement) {
action.addAction(new MoveMouseAction(driver, toElement));
return this;
}

On Dec 5, 5:59 pm, Simon Stewart <simon.m.stew...@gmail.com> wrote:
> You could try using the Advanced User Interactions APIs, which are
> designed for exactly this sort of case:
>
> Action action = new ActionChainsGenerator(driver)
>   .moveToElement(firstElement)
>   .click(secondElement)
>   .build();
> action.perform();
>
> Cheers,
>

Simon Stewart

unread,
Dec 6, 2010, 9:16:55 AM12/6/10
to webd...@googlegroups.com
It looks like the FirefoxDriver doesn't implement HasInputDevices yet.
Eran's working on it, I think.

Simon

Eran M.

unread,
Dec 6, 2010, 12:08:27 PM12/6/10
to webd...@googlegroups.com
That's right - currently the HtmlUnit driver implements the intractions API and IE implements parts of it and I plan to complete support for Firefox and IE by the end of the month.

Eran

hairinwind

unread,
Dec 6, 2010, 2:54:45 PM12/6/10
to webdriver
Does it work? I tried but still complained second element cannot be
found.

Here is my testing html.
<style type="text/css">
ul:hover ul {
display:block
}

ul ul {
display:none
}
</style>


<ul id="nav">
<li><a href="">first level 1</a></li>
<ul>
<li><a href="">second level 1</a></li>
</ul>
</ul>

Here is my test

Action action = new ActionChainsGenerator(driver)
.moveToElement(driver.findElement(By.linkText("first level 1")))
.click(driver.findElement(By.linkText("second level 1")))
.build();
action.perform();

Here is the error:

org.openqa.selenium.NoSuchElementException: No link found with text:
second level 1
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_02'
Driver info: driver.version: htmlunit
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByLinkText(HtmlUnitDriver.java:
576)
at org.openqa.selenium.By$2.findElement(By.java:93)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:
1150)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:
344)


On Dec 5, 9:59 am, Simon Stewart <simon.m.stew...@gmail.com> wrote:
> You could try using the Advanced User Interactions APIs, which are
> designed for exactly this sort of case:
>
> Action action = new ActionChainsGenerator(driver)
>   .moveToElement(firstElement)
>   .click(secondElement)
>   .build();
> action.perform();
>
> Cheers,
>
> Simon
>

SV

unread,
Dec 7, 2010, 12:22:03 PM12/7/10
to webdriver
Hi, Simon.

I've done as you said but there was the following exception:
java.lang.UnsupportedOperationException: Mouse is not implemented yet
for the remote WebDriver.
at
org.openqa.selenium.remote.RemoteWebDriver.getMouse(RemoteWebDriver.java:
369)
at
org.openqa.selenium.internal.interactions.BaseAction.getMouse(BaseAction.java:
43)
at
org.openqa.selenium.interactions.MoveMouseAction.perform(MoveMouseAction.java:
35)
at
org.openqa.selenium.interactions.CompositeAction.perform(CompositeAction.java:
31)

Can you help me with this problem?

Simon Stewart

unread,
Dec 7, 2010, 1:23:25 PM12/7/10
to webd...@googlegroups.com
Eran's working on the user interactions API, and plans to get Firefox
done after the IE driver (so, hopefully, this month)

Simon

Binken

unread,
Dec 7, 2010, 11:22:52 PM12/7/10
to webdriver
Both the Java and the .net?

Simon Stewart

unread,
Dec 8, 2010, 5:13:04 AM12/8/10
to webd...@googlegroups.com
Java first. I expect there to be some flux in that API as we explore
new use cases, but I also expect the ActionChainsGenerator to be one
of the more stable points in that flux.

Simon

Jason Leyba

unread,
Dec 8, 2010, 5:18:07 AM12/8/10
to webd...@googlegroups.com
Java only at first

Binken

unread,
Dec 8, 2010, 7:51:44 PM12/8/10
to webdriver
I am looking at the ActionChainsGenerator java code. And trying to
convert to the C# one. And I wanna to know how to modify the
firefoxdriver to implents the HasInputDevice interface

Simon Stewart

unread,
Dec 9, 2010, 5:41:39 AM12/9/10
to webd...@googlegroups.com
There's a few moving pieces. First the wire protocol needs to be
modified (which, other than picking the correct URLs is easy :) The
next is to implement "HasInputDevices" on the FirefoxDriver (or the
equivalent for C#). Finally, the JS code in the firefox driver needs
to be modified. This isn't too hard either.

The problem is that it's fairly time consuming. Eran's working on the
IE driver first since that's the easiest for him to iterate on as he's
working on the code. The advanced user interactions API makes
extensive use of the native events library: it's likely that this
needs modification. That's the thing that soaks up the time.

Please, however, feel free to get involved. It's one of the more
interesting parts of the codebase IMO.

Simon

Binken

unread,
Dec 24, 2010, 2:01:31 AM12/24/10
to webd...@googlegroups.com
I think this part has not completed in the beta 1

Svilen Velikov

unread,
Dec 24, 2010, 2:38:37 AM12/24/10
to webd...@googlegroups.com
Hi,
You can use native events to activate the menu. Also js can be used. It depends on the case you have. Reading the doc for selenium2 you will notice that you are allowed to drive the system under test only the way a user can interact with it. In other words, you can't click hidden elements for example, but can hover the top level menu in order to get access to the sub menus and click them.

On Fri, Dec 24, 2010 at 9:01 AM, Binken <binke...@gmail.com> wrote:
I think this part has not completed in the beta 1 --
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.



--
Поздрави

Свилен Великов

jonm42

unread,
Jan 7, 2011, 5:00:59 PM1/7/11
to webdriver
Was this addressed in 2.0b1? I'm using the firefox driver on Mac OS X
10.6.6 and get the following traceback during test case setup when
trying to set a driver

java.lang.NoClassDefFoundError: org/openqa/selenium/HasInputDevices
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at
com.yesmail.enterprise.testutils.ExtendedSeleneseTestCase.setDriver(ExtendedSeleneseTestCase.java:
148)
at
com.yesmail.enterprise.testutils.ExtendedSeleneseTestCase.setUp(ExtendedSeleneseTestCase.java:
97)
at com.yesmail.enterprise.ImportLinkTest.setUp(ImportLinkTest.java:
31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at org.junit.runners.model.FrameworkMethod
$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:
15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:
41)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
27)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
31)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
76)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
65)
Caused by: java.lang.ClassNotFoundException:
org.openqa.selenium.HasInputDevices
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 48 more



On Dec 9 2010, 2:41 am, Simon Stewart <simon.m.stew...@gmail.com>
wrote:

Dreamer

unread,
Jan 11, 2011, 6:25:07 AM1/11/11
to webdriver
Hi Eran,

Any joy with clicking hidden Menu, by hovering on the parent menu
yet..

Dreamer


On Dec 6 2010, 5:08 pm, "Eran M." <eran....@gmail.com> wrote:
> That's right - currently the HtmlUnit driver implements the intractions API
> and IE implements parts of it and I plan to complete support for Firefox and
> IE by the end of the month.
>
> Eran
>
> On 6 December 2010 14:16, Simon Stewart <simon.m.stew...@gmail.com> wrote:
>
>
>
>
>
>
>
> > It looks like the FirefoxDriver doesn't implement HasInputDevices yet.
> > Eran's working on it, I think.
>
> > Simon
>
> > webdriver+...@googlegroups.com<webdriver%2Bunsubscribe@googlegroups .com>
> > .
> > >> > For more options, visit this group athttp://
> > groups.google.com/group/webdriver?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > "webdriver" group.
> > > To post to this group, send email to webd...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > webdriver+...@googlegroups.com<webdriver%2Bunsubscribe@googlegroups .com>
> > .
> > > For more options, visit this group at
> >http://groups.google.com/group/webdriver?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "webdriver" group.
> > To post to this group, send email to webd...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > webdriver+...@googlegroups.com<webdriver%2Bunsubscribe@googlegroups .com>
> > .
Reply all
Reply to author
Forward
0 new messages