【问题标题】:Error using gecko driver script for Selenium 3.11使用 Selenium 3.11 的壁虎驱动程序脚本时出错
【发布时间】:2018-09-07 13:27:18
【问题描述】:

我正在使用 Selenium 3.11 版、gecko 驱动程序 v0.20 和 Firefox 59 版。我使用了 system.setproperty 脚本,但我仍然收到此错误:

线程“main”java.lang.IllegalStateException 中的异常:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置

我也用 Firefox v40 试过这个。 请帮我解决这个问题。谢谢。

我使用的语法如下: System.setProperty("webdriver.gecko.driver","C:\geckodriver.exe");

【问题讨论】:

标签: java


【解决方案1】:

感谢您的回复。在环境变量设置中设置 geckodriver 路径后,我的问题得到解决。 但是谁能帮我解决一个问题:哪个最新的 firefox 版本将支持 firebug 和 xpath 插件?

【讨论】:

    【解决方案2】:

    尝试做这样的事情:

    public void loadSystemProperties() {
            try {
                InputStream in = getClass().getResourceAsStream("/geckodriver");
                File file = stream2file(in);
                System.setProperty("webdriver.gecko.driver", file.getAbsolutePath());
                LOGGER.info("Geckdriver found at {}", file.getAbsoluteFile());
            } catch (IOException e) {
                LOGGER.error(e.getMessage());
            }
    }
    
    
    static File stream2file(InputStream in) throws IOException {
            String PREFIX = "stream2file";
            String SUFFIX = ".tmp";
            final File tempFile = File.createTempFile(PREFIX, SUFFIX);
            tempFile.deleteOnExit();
            try (FileOutputStream out = new FileOutputStream(tempFile)) {
                IOUtils.copy(in, out);
            }
            tempFile.setExecutable(true);
            return tempFile;
        }
    

    我正在使用 2.6 版的 commons-io。另外,我的 geckodriver 在我的资源文件夹中。

    【讨论】:

      猜你喜欢
      • 2017-07-30
      • 1970-01-01
      • 2020-08-23
      • 2018-01-20
      • 1970-01-01
      • 2018-03-17
      • 2018-06-19
      • 1970-01-01
      • 2016-10-07
      相关资源
      最近更新 更多