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 have set the path correctly, still don't know where the problem is. Here is my code:
if (browsers.equalsIgnoreCase("Firefox"))
{
String driverPath = System.getProperty("user.dir") + "\\src/test/java\\drivers\\geckodriver.exe";
System.setProperty("webdriver.firefox.marionette", "false");
driver = new FirefoxDriver();
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);
}
Here is the Failure Trace of my code:
FAILED CONFIGURATION: @BeforeClass launchBrowser
org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities
Build info: version: '3.8.0', revision: '924c4067df', time: '2017-11-30T11:36:59.109Z'
System info: host: 'DSCHD-PC-180', ip: '192.168.6.122', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'
Driver info: driver.version: FirefoxDriver
remote stacktrace:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new0ドル(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction2ドル(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession0ドル(ProtocolHandshake.java:123)
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at Utility.UtilityMethods.openBrowser(UtilityMethods.java:26)
at TestCases.LoginTestCase.launchBrowser(LoginTestCase.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
SKIPPED CONFIGURATION: @AfterClass quitBrowser
SKIPPED: registration
-
This is a potential duplicate issue. Please see the following: stackoverflow.com/questions/38676719/…Larry– Larry2018年04月12日 07:03:31 +00:00Commented Apr 12, 2018 at 7:03
5 Answers 5
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();
Update
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 :
- GeckoDriver v0.17.0
- GeckoDriver v0.16.1
-
2This code is giving me error " Unable to find a matching set of capabilities", That mean it did not have set the capability marionatte to "false"Rohn Kerry– Rohn Kerry2018年04月12日 10:50:26 +00:00Commented Apr 12, 2018 at 10:50
-
1Just to update you , I have done some changes- dc.setCapability("marionatte", false); FirefoxDriver driver = new FirefoxDriver(dc); ....This have initiated the Firefox browser but now I am getting the error "connection refused", Why is this happening?Rohn Kerry– Rohn Kerry2018年04月12日 11:12:13 +00:00Commented Apr 12, 2018 at 11:12
-
@RohnKerry Update the question with the complete error stack trace for further analysis pleaseundetected Selenium– undetected Selenium2018年04月12日 11:18:22 +00:00Commented Apr 12, 2018 at 11:18
-
1I have found the solution for that. The code is : System.setProperty("webdriver.firefox.marionette","D:\\geckodriver.exe");Rohn Kerry– Rohn Kerry2018年04月12日 12:08:52 +00:00Commented Apr 12, 2018 at 12:08
-
1My geckodriver version is- geckodriver-v0.20.1Rohn Kerry– Rohn Kerry2018年04月13日 05:32:16 +00:00Commented Apr 13, 2018 at 5:32
This is how system property is set:
System.setProperty("webdriver.gecko.driver", "C:\\...\\geckodriver.exe");
I had this error for 2 days, the solution for me was in Set.Platform, put Platform.ANY or Platform.Windows because Platform.WIN10 not worked, marionette wasn't necessary.
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
}
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.
-
That is correct but the issue is, I am using firefox version 37, So I have to put marionette= false. Now we can send only two string values in .setProperty.So where I can put the path to the geckodriver?Rohn Kerry– Rohn Kerry2018年04月12日 07:18:38 +00:00Commented Apr 12, 2018 at 7:18
-
Which version of selenium you are using with FF37?cruisepandey– cruisepandey2018年04月12日 07:19:27 +00:00Commented Apr 12, 2018 at 7:19
-
Like can we do that- System.setProperty("webdriver.firefox.marionette=false", "driverPath"); ?Rohn Kerry– Rohn Kerry2018年04月12日 07:19:31 +00:00Commented Apr 12, 2018 at 7:19
-
I am using selenium 3.11.0Rohn Kerry– Rohn Kerry2018年04月12日 07:21:06 +00:00Commented Apr 12, 2018 at 7:21
-
@RohnKerry : I'm not sure about this. Give me some time, if I will find anything, I will update you !cruisepandey– cruisepandey2018年04月12日 07:23:26 +00:00Commented Apr 12, 2018 at 7:23
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.
-
But the problem is I am not using latest firefox version, I am using ff version 37. That is why I have set the marionette= false, for compatibility.Rohn Kerry– Rohn Kerry2018年04月12日 07:22:51 +00:00Commented Apr 12, 2018 at 7:22
-
@RohnKerry, the latest Firefox version is 59 and you don't need to set marionette for that if you are using ff version 37 then you have to use compatible
firefoxdriver.exe
BhavinD.– BhavinD.2018年04月12日 07:42:28 +00:00Commented Apr 12, 2018 at 7:42 -
So you mean to say that I have to download a compatible Firefox Webdriver for ff version 37?Rohn Kerry– Rohn Kerry2018年04月12日 08:13:14 +00:00Commented Apr 12, 2018 at 8:13
-
No need to download. you can use latest FireFox geckodriver and you can set marionette=false using DesiredCapabilities class.BhavinD.– BhavinD.2018年04月12日 08:39:48 +00:00Commented Apr 12, 2018 at 8:39
-
Yes I have already did that but the problem is you can pass two values to the .setProperty() and I have to also give path to geckodriver in that.Rohn Kerry– Rohn Kerry2018年04月12日 09:53:56 +00:00Commented Apr 12, 2018 at 9:53
Explore related questions
See similar questions with these tags.