【问题标题】:The driver executable does not exist: D:\Firefox\geckodriver.exe驱动程序可执行文件不存在:D:\Firefox\geckodriver.exe
【发布时间】:2017-12-01 13:20:52
【问题描述】:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class sasas {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.gecko.driver","D:\\Firefox\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();

        String appUrl = "https://accounts.google.com";
        driver.manage().window().maximize();
        driver.get(appUrl);
        System.out.println("Test script executed successfully.");
        driver.close();
    }
}

这是我正在尝试的示例代码。当我运行时,我收到错误消息 “驱动程序可执行文件不存在:D:\Firefox\geckodriver.exe” 请帮助我继续。我在环境变量中添加了位置,然后我也收到了这个错误。 PATH 我添加为 D:\Samplecode。

请帮帮我

【问题讨论】:

  • geckodriver.exe 文件保存在哪里?

标签: java selenium


【解决方案1】:

(1) 要使用 gecko 驱动,请确保您使用的是 Firefox 55 及以上版本以获得更好的 gecko Web-Driver 功能支持,了解更多here

(2) 也许,您应该将 Selenium 降级到较低版本,即 2.53.1 版。 Selenium 2.53.1 版在 Firefox 47.0.1 及更低版本上完美运行,不需要使用 Web 驱动程序 API。我已经针对这个运行了你的代码,它运行良好。

公共类 Sasas {

public static void main(String[] args) {

    WebDriver driver = new FirefoxDriver();

    String appUrl = "https://accounts.google.com";
    driver.manage().window().maximize();
    driver.get(appUrl);
    System.out.println("Test script executed successfully.");
    driver.close();
}

}

【讨论】:

    【解决方案2】:

    使用相对路径:

    JAVA

    1.- 在您的项目中,创建 Drivers/Win/Firefox/geckodriver.exe 文件夹并添加您的 .exe

    2.- 替换:

    System.setProperty("webdriver.gecko.driver","D:\\Firefox\\geckodriver.exe");
    

    为:

    String path = System.getProperty("user.dir") + "/Drivers/Win/Firefox/Geckodriver.exe";
    
    System.setProperty("webdriver.gecko.driver", path);
    

    注意:使用相对路径是最优的

    【讨论】:

      猜你喜欢
      • 2017-04-08
      • 2018-05-19
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多