testbench
testbench copied to clipboard
Clicking MenuBar doesn't work: "Vaadin could not find elements with the selector"
Vaadin 8.8.5 TestBench 5.2.0 Using latest ChromeDriver 76.0.3809.68 and Chrome 76.0.3809.100 (Official Build) (64-bit) in Windows 10 Pro. (Tomcat 8.5.34, jdk1.8.0_202)
Using simple example MenuBar demo:
MenuBar menuBar = new MenuBar();
menuBar.setId("main-navigation");
menuBar.addItem("item1");
MenuBar.MenuItem topItem2 = menuBar.addItem("item2");
topItem2.setIcon(VaadinIcons.ABACUS);
MenuBar.MenuItem subItem1 = topItem2.addItem("subItem1", cmd -> {
System.out.println("Subitem1 clicked");
});
subItem1.setIcon(VaadinIcons.DASHBOARD);
topItem2.addItem("subitem2");
And different TestBench tests:
$(MenuBarElement.class).id("main-navigation").clickItem("item2", "subItem1");
MenuBarElement menu = $(MenuBarElement.class).id("main-navigation");
menu.findElement(By.vaadin("#item2")).click();
menu.findElement(By.vaadin("#subItem1")).click();
These fails to:
org.openqa.selenium.NoSuchElementException: Vaadin could not find elements with the selector #item2
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'LAPTOP-FK6OGBCP', ip: '192.168.99.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202'
Driver info: driver.version: unknown
at com.vaadin.testbench.TestBenchDriverProxy.findElementByVaadinSelector(TestBenchDriverProxy.java:110)
at com.vaadin.testbench.By$ByVaadin.findElement(By.java:69)
at com.vaadin.testbench.TestBenchElement.findElement(TestBenchElement.java:289)
at org.test.charttest.TestBenchTest.test(TestBenchTest.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.Exception: Client could not identify elements with the provided selector
... 29 more
Ugly workaround, this was only way to make it work. It is tricky because you have to find a correct index for the submenu item and query from "root" using getDriver
MenuBarElement menu = $(MenuBarElement.class).id("main-navigation");
menu.findElements(By.className("v-menubar-menuitem")).get(1).click();
getDriver().findElements(By.className("v-menubar-menuitem")).get(2).click();