运行Gecko Driver的Selenium脚本时出现"org.openqa.selenium.WebDriverException: Unsupported Marionette protocol version 2"错误。

3

我刚开始学习 Selenium Java。我正在使用 Selenium Beta 3Mozilla Firefox v43 运行我的脚本。以下是我的代码:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class RegistrationFirefox {

    public static void main(String[] args) 
    {
        System.setProperty("webdriver.gecko.driver", "C:\\SeleniumDrivers\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();

        driver.get("http://www.google.com");
        System.out.println(driver.getTitle());
        driver.manage().window().maximize();    
        driver.close();
    }    
}

最初,我遇到了以下错误:

"Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver

在安装了geckodriver之后,我遇到了以下错误(上面提到的代码):

Exception in thread "main" org.openqa.selenium.WebDriverException: Unsupported Marionette protocol version 2, required 3 (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 5.26 seconds

请注意,在翻译过程中保留了HTML标签。
1个回答

4

"主线程中的异常"java.lang.IllegalStateException: 必须通过webdriver.gecko.driver设置驱动程序可执行文件的路径

实际上,Selenium 3支持使用geckodriver可执行文件与其他驱动程序一样使用Mozilla Firefox。这就是为什么您会收到此异常。

要解决此问题,您需要将此可执行文件geckodriver设置为系统属性,并使用webdriver.gecko.driver已经完成了这个步骤。

主线程中的异常"org.openqa.selenium.WebDriverException: 不支持的Marionette协议版本2,需要3(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:5.26秒

现在的问题在于你的Mozilla版本。实际上可执行文件 geckodriver支持 Mozilla Firefox >= v47,这就是为什么你会得到这个异常。
为了解决这个问题,你需要升级你的 Mozilla Firefox >= v47

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接