I am trying to run test a run a website in Firefox, but I am getting error \"The path to the driver executable must be set by the webdriver.gecko.driver system property;\" I
I haved this error for 2 days, the solution for me was in Set.Plataform put Platafor.ANY or Plataform.Windows because Plataform.WIN10 not worked, marionette wasn't necessary and I added and neether works, only works this. I hope this helps someone else:
public class Main { public static RemoteWebDriver driver;
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "D:/Lib/geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities().firefox();
desiredCapabilities.setPlatform(Platform.ANY);
desiredCapabilities.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://172.20.19.182:5557/wd/hub"), desiredCapabilities);
driver.navigate().to("http://www.google.com");
driver.findElementByName("q").sendKeys("execute automation");
driver.findElementByName("q").sendKeys(Keys.ENTER);
driver.close();
// write your code here
}
Just updated your code. You will have to set driver path while setProperty
and user webdriver.gecko.driver
for latest firefox driver.
if (browsers.equalsIgnoreCase("Firefox")) {
String driverPath = System.getProperty("user.dir") + "\\src\\test\\java\\drivers\\geckodriver.exe";
System.setProperty("webdriver.firefox.driver", "driverPath");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("marionette", false);
FirefoxOptions options = new FirefoxOptions();
options.merge(capabilities);
FirefoxDriver driver = new FirefoxDriver(options);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
else if (browsers.equalsIgnoreCase("Chrome")) {
// String driverPath = System.getProperty("user.dir") +
// "\\src\\Drivers\\chromedriver";
// System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
Let me know.
To keep things simple, as you are using Selenium Client v3.11.0 and Firefox v37 you need to download the latest GeckoDriver from mozilla/geckodriver and save it any where within your system. Next within the System.setProperty()
line pass the Key webdriver.gecko.driver along with the Value as the absolute path of the GeckoDriver and finally through DesiredCapabilities class set the capability marionatte to false and merge into an instance of FirefoxOptions instance to initiate the Firefox browser as follows :
System.setProperty("webdriver.gecko.driver", "C:/path/to/geckodriver.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
FirefoxDriver driver = new FirefoxDriver(opt);
driver.get("https://stackoverflow.com");
System.out.println("Application opened");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
As per your comment update you are using GeckoDriver v0.20.1.
But if you look back at the Release Notes of GeckoDriver v0.18.0 it clearly mentions :
geckodriver now recommends Firefox 53 and greater
So using GeckoDriver v0.18.0 and above you have to mandatory use Firefox 53 and greater. To get rid of this constraint you can downgrade either to any of these versions :
This is how system property is set:
System.setProperty("webdriver.gecko.driver", "C:\\...\\geckodriver.exe");
you are using user.dir that basically means : current working directory
Here is the code that let you initialize firefox browser using selenium.
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\your\\gecko\\driver\\path\\geckodriver.exe");
driver = new firefoxDriver();
That's it ! you can use Firefox driver to performs several operations like :
1. driver.get(String args0);
2. driver.getCurrentUrl();
3. driver.getPageSource();
4. driver.getTitle();
5. driver.findElememt(By args0);
6. driver.findElements(By args0);
7. driver.naviagate();
8. driver.manage();
9. driver.close();
10. driver.quit();
11. driver.switchTo();
12. driver.getWindowHandle();
13. driver.getWindowHandles();
Please let me know if you have any concerns related to this.