Junit:NoSuchElement仅在remotewebriver中运行测试时出现异常

时间:2014-01-30 14:35:56

标签: java selenium selenium-webdriver junit4 selenium-grid

我使用selenium网格与2个节点并行运行10个测试,仅在NoSuchElementException得到Remotewebdriver,但在普通的firefox驱动程序中工作正常,

我已经定义了我自己的threadpool执行器类,它一次拥有两个线程,每个线程使用Junitcore api开始自己的Junit测试。

以下是我收到的例外

  

org.openqa.selenium.NoSuchElementException:无法找到元素:{“method”:“id”,“selector”:“login_element”}   命令持续时间或超时:1.28秒   构建信息:版本:'2.35.0',修订版:'c916b9d',时间:'2013-08-12 15:42:01'   系统信息:os.name:'Windows 7',os.arch:'x86',os.version:'6.1',java.version:'1.6.0_24'   会议ID:5c94133a-5586-449c-b7f6-018bbd79a6d7   驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver   功能[{platform = XP,acceptSslCerts = true,javascriptEnabled = true,browserName = firefox,rotata   ble = false,locationContextEnabled = true,version = 23.0.1,cssSelectorsEnabled = true,databaseEnabled = tr   ue,handlesAlerts = true,browserConnectionEnabled = true,nativeEvents = true,webStorageEnabled = true,ap   plicationCacheEnabled = true,takeScreenshot = true}]           at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)           at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:   39)           at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorIm)   pl.java:27)           at java.lang.reflect.Constructor.newInstance(Constructor.java:513)           在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191)           在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)           在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)           在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)           在org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:356)   )           在org.openqa.selenium.By $ ByLinkText.findElement(By.java:241)           在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)           at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)           在java.lang.reflect.Method.invoke(Method.java:597)           在org.openqa.selenium.support.events.EventFiringWebDriver $ 2.invoke(EventFiringWebDriver.jav)   一:101)           在$ Proxy1.findElement(未知来源)           在org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver。   的java:180)           在org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:47)           在org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:1)           at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:303)           在java.util.concurrent.FutureTask.run(FutureTask.java:138)           在org.openqa.selenium.remote.server.DefaultSession $ 1.run(DefaultSession.java:169)           at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886)           at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908)           在java.lang.Thread.run(Thread.java:662)

还尝试了一些示例小测试,工作正常,没有任何异常,只有在我运行我的应用程序时才会出现问题

请在此提供您的意见

1 个答案:

答案 0 :(得分:0)

您是否尝试等待该元素?我建议你使用WebDriverWait

WebDriverWait wait = new WebDriverWait(driver,120/*timeout in seconds*/);
WebElement login = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login_element")));
//do stuff with login