in my case, I must to set path in properties file, in many hours I find the way:
webdriver.gecko.driver="/lib/geckodriver-v0.26.0-win64/geckodriver.exe"
in java code:
private static final Logger log = Logger.getLogger(Login.class.getName());
private FirefoxDriver driver;
private FirefoxProfile firefoxProfile;
private final String BASE_URL = "https://www.myweb.com/";
private static final String RESOURCE_NAME = "main/resources/application.properties"; // could also be a constant
private Properties properties;
public Login() {
init();
}
private void init() {
properties = new Properties();
try(InputStream resourceStream = getClass().getClassLoader().getResourceAsStream(RESOURCE_NAME)) {
properties.load(resourceStream);
} catch (IOException e) {
System.err.println("Could not open Config file");
log.log(Level.SEVERE, "Could not open Config file", e);
}
// open incognito tab by default
firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.privatebrowsing.autostart", true);
// geckodriver driver path to run
String gekoDriverPath = properties.getProperty("webdriver.gecko.driver");
log.log(Level.INFO, gekoDriverPath);
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + gekoDriverPath);
log.log(Level.INFO, System.getProperty("webdriver.gecko.driver"));
System.setProperty("webdriver.gecko.driver", System.getProperty("webdriver.gecko.driver").replace("\"", ""));
if (driver == null) {
driver = new FirefoxDriver();
}
}