selenium 无法打开 firefox 浏览器说 NoclassDefFounderror

selenium could not open firefox browser says NoclassDefFound error

我们使用带有 gecko 驱动程序 (v0.11.1) 和 firefox 49 版的 selenium 3.0.1。当我们尝试使用此代码

触发 firefox 浏览器时
     System.setProperty("webdriver.gecko.driver",gecko_driver_path );
     WebDriver driver = new FirefoxDriver();        
     driver.manage().window().maximize();
     return driver;

我们收到此错误

     java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException
     at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
     at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
     at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
     at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
     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:497)
     at cucumber.runtime.Utils.call(Utils.java:37)

请帮帮我。

您必须添加 selenium-standalone server jar 依赖如下:

If you are using DefaultSelenium (or the RemoteWebDriver implementation), you still need to start a Selenium server. The best way is to download the selenium-server-standalone.jar from the Selenium Downloads page and just use it. Furthermore you can also embed the Selenium server into your own project, if you add the following dependency to your pom.xml:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>3.0.1</version>
</dependency> 

参考:

  1. http://www.seleniumhq.org/download/maven.jsp