线程 "main" java.lang.IllegalStateException 中的异常:驱动程序可执行文件不存在:/Users/Golcha/Desktop/Automation/geckodriver.exe

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /Users/Golcha/Desktop/Automation/geckodriver.exe

出现以下错误

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /Users/Golcha/Desktop/Automation/geckodriver.exe

代码:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class selenium{

    private static WebDriver driver;

    public static void main(String[]args){

        System.setProperty("webdriver.gecko.driver","Users/Golcha/Desktop/Automation/geckodriver.exe");

        setDriver(new FirefoxDriver());
    }

    public static WebDriver getDriver() {
        return driver;
    }

    public static void setDriver(WebDriver driver) {
        selenium.driver = driver;
    }

}

尝试下面的代码,但在执行下面的代码之前正确检查 geckodriver 的路径,否则我建议您将 geckodriver 粘贴到 C 驱动器或任何其他驱动器中以制作您的路径简单如下:

System.setProperty("webdriver.firefox.marionette", "C:\geckodriver.exe");  

它应该可以正常工作。祝一切顺利!

我想你没有在你的 System.setProperty() 方法中提到 Geckodriver 的完整(完整)路径.你错过了盘符 "C"

"C:/Users/Golcha/Desktop/Automation/geckodriver.exe"

如果这解决了您的问题,请告诉我。

我有一个类似的问题,但奇怪的是我无法在我的两个驱动程序(chrome 和 firefox)上执行 selenium 脚本,我尝试检查我的 setProperty 方法,我的 gecko 驱动程序路径和 chrome 驱动程序路径。最后,我尝试更新我的浏览器,它现在似乎可以正常工作了。 (我当前的 Chrome 版本是 66,我当前的 Firefox 版本是 56.0)。