You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Firefox 59.0.3与GeckoDriver 0.15执行Selenium脚本时遇UnsupportedCommandException

解决Selenium 3.3.1 + GeckoDriver 0.15 + Firefox 59的timeouts不支持错误

问题场景

作为Selenium初学者,我使用以下环境组合执行自动化代码时遇到了错误:

  • Selenium-Java-3.3.1
  • Firefox 59.0.3(64位)
  • GeckoDriver 0.15

执行的代码如下:

import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.firefox.FirefoxOptions; 

public class TestClass { 
    WebDriver driver; 

    public void invokeBrowser() { 
        try { 
            System.setProperty("webdriver.gecko.driver", "D:\\GEGDC\\KT00475829\\Downloads\\geckodriver-v0.15.0-win64\\geckodriver.exe"); 
            driver = new FirefoxDriver(); 
            driver.manage().deleteAllCookies(); 
            driver.manage().window().maximize(); 
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
            driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); 
            driver.get("https://stg2-magic.health.ge.com:13007/enovia/common/emxNavigator.jsp"); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    } 

    public static void main(String args[]) { 
        TestClass myObj = new TestClass(); 
        myObj.invokeBrowser(); 
    } 
}

执行后抛出错误:

org.openqa.selenium.UnsupportedCommandException: timeouts 
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10 09:00:17 -0800' 
System info: host: 'TMIC-PCS2200', ip: '3.235.34.200', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144' 
Driver info: org.openqa.selenium.firefox.FirefoxDriver

问题根源

这个错误本质是版本兼容性不匹配:GeckoDriver 0.15是2017年的老旧版本,对W3C WebDriver协议的支持不完善,而Firefox 59已经开始全面支持W3C协议,两者在timeouts相关命令的交互上出现了不兼容,导致Selenium无法正确执行超时设置的命令。

修复方案

1. 优先升级GeckoDriver到兼容版本

Firefox 59对应的推荐GeckoDriver版本是v0.20.1(该版本兼容Firefox 55~60版本)。你只需要:

  • 下载对应Windows 64位的GeckoDriver v0.20.1
  • 替换代码中指定的旧版GeckoDriver路径

2. 优化超时设置代码(可选但推荐)

Selenium 3.x开始推荐使用Duration类替代TimeUnit来设置超时,写法更简洁且符合新的API规范,你的Java 1.8环境完全支持:

// 替换原来的两行超时设置代码
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));

3. 临时 workaround(不推荐长期使用)

如果暂时无法升级GeckoDriver,可以尝试启用旧版Legacy协议来兼容,但会限制新功能使用:

// 在初始化FirefoxDriver前添加以下代码
FirefoxOptions options = new FirefoxOptions();
options.setLegacy(true);
driver = new FirefoxDriver(options);

内容的提问来源于stack exchange,提问作者kiran kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:05:40