没有浏览器启动 - Selenium Webdriver - java.lang.NoClassDefFoundError:com / google / gson / JsonElement

时间:2017-04-09 04:12:03

标签: java eclipse selenium selenium-webdriver

我有以下非常简单的代码:

System.setProperty("webdriver.chrome.driver", ECC.CHROME_DRIVER_PATH);
        WebDriver x = new ChromeDriver();
        x.get("www.google.com");

这引发:

java.lang.NoClassDefFoundError: com/google/gson/JsonElement
     at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:139)
     at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
     at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
     at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
     at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
     at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
     at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:178)
     at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:167)
     at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
     at com.axletrees.tests.draft.In_Dev_Tests_Jorge.verifyLoginAD(In_Dev_Tests_Jorge.java:24)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
     at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
     at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)  at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
     at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
     at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
     at org.testng.TestRunner.privateRun(TestRunner.java:744)
     at org.testng.TestRunner.run(TestRunner.java:602)
     at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
     at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
     at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
     at org.testng.SuiteRunner.run(SuiteRunner.java:289)
     at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
     at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
     at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
     at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
     at org.testng.TestNG.runSuites(TestNG.java:1144)
     at org.testng.TestNG.run(TestNG.java:1115)
     at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
     at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
     at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: java.lang.ClassNotFoundException: com.google.gson.JsonElement 
     at java.net.URLClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     ... 35 more

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

以下是您的问题的解决方案:

  1. 您需要提供如下所示的cromedriver的完整路径:
  2. System.setProperty("webdriver.chrome.driver", ECC.CHROME_DRIVER_PATH+"cromedriver.exe");

    1. 您需要提供调用网页的协议: WebDriver x = new ChromeDriver(); x.get("http:\\google.com");
    2. 如果这有助于您,请告诉我。

答案 1 :(得分:0)

我可以通过eclipse市场更新TestNG来解决这个问题。我有pom.xml文件中指定的最新版本,我没有在eclipse中手动更新TestNG。

如果有人遇到同样的问题,那么当他去市场看安装的应用程序时,有时它不会提供更新应用程序的可能性,它只会说&#34;安装&#34 ;;要查看是否有任何更新,请单击&#34;安装&#34;按钮,你会看到选项。

再次感谢您的帮助。