0

I am not able to launch Firefox browser using geckodriver in Selenium 3.8.1

This is my code

public class LoginTest {
    @SuppressWarnings("deprecation")
    @Test
    public static void logintest() {
        System.setProperty("webdriver.gecko.driver",
            "C:\\Users\\abc\\Downloads\\geckodriver.exe");
        DesiredCapabilities dc = DesiredCapabilities.firefox();
        dc.setCapability("marionnete", true);
        constants.driver = new FirefoxDriver(dc);
        constants.driver.get("https://www.amazon.in");
        constants.driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        constants.driver.manage().window().maximize();
    }

I am not able to understand why it is not working and always giving an exception

org.openqa.selenium.SessionNotCreatedException`: Unable to find a matching set of capabilities
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12- 01T18:33:54.468Z'<br>
System info: host: 'ABC-VAIO', ip: '192.168.1.209', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'<br>
Driver info: driver.version: FirefoxDriver
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Ab123
  • 395
  • 1
  • 10
  • 31
  • First of all make sure your **geckodriver version** is compatible with the **Selenium version**. This is the number one mistake when using Selenium with any browser. Make sure the capabilities you provide are correct and you didn't forget anything. Best is to look out for the official examples or a program from somebody else that works. In doubt, try out older driver versions with older Selenium versions. – Zabuzard Apr 30 '18 at 16:17
  • I was using selenium 3.8.1 and downloaded latest gecko driver from github, also how can i check the compatibility. – Ab123 Apr 30 '18 at 16:21
  • Selenium is already at 3.11 ... 'Support is best in Firefox 55 and greater, although generally the more recent the Firefox version, the better the experience as they have more bug fixes and features', see https://github.com/mozilla/geckodriver – Marged Apr 30 '18 at 16:23
  • Yes i know i forcely downgraded to 3.8.0 because it was also not working for 3.11 – Ab123 Apr 30 '18 at 16:24
  • Possibly this is the same issue ? https://stackoverflow.com/questions/40106844/selenium-3-0-firefx-driver-fails-with-org-openqa-selenium-sessionnotcreatedexcep – Marged Apr 30 '18 at 16:27
  • The last time I used Selenium with Firefox, I used **Selenium 3.4.0** on **Firefox ESR 45** with **geckodriver v0.15.0 for arm7hf**. This were my `Capabilities`: https://i.imgur.com/974pD4k.png (see [here](https://raspberrypi.stackexchange.com/a/67631) for more) – Zabuzard Apr 30 '18 at 16:31
  • I have downgraded selenium to 3.0 and downgraded gecko driver to 0.15 and now browser got launched but not getting maximized and getting exception: org.openqa.selenium.WebDriverException: An unknown error has occurred Build info: version: '3.3.0', revision: 'b526bd5b41', time: '2017-03-07 1 – Ab123 Apr 30 '18 at 16:41

2 Answers2

0

You should add capabilities for firefox Please modify your code as follows :

System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setVersion("your firefox version");
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("https://www.amazon.in");
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
0

This error message...

org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities

...implies that the FirefoxDriver didn't find a matching set of capability while initiating a new WebBrowser session.

You are using Selenium Client v3.8.1 but the Release Notes of Selenium Client v3.7.0 clearly states that :

* Migrated from using `DesiredCapabilities` to either
  `MutableCapabilities` or (preferably) `ImmutableCapabilities`.

So, you have to use the merge() method from MutableCapabilities Class to add the capabilities within an instance of FirefoxOptions and pass the FirefoxOptions object while initializing the Firefox Browser as follows :

System.setProperty("webdriver.gecko.driver", "C:\\Users\\abc\\Downloads\\geckodriver.exe");
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability("marionnete", true);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
constants.driver = new FirefoxDriver(opt);
constants.driver.get("https://www.amazon.in");
DebanjanB
  • 118,661
  • 30
  • 168
  • 217