Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find a matching set of capabilities with selenium 3.8.1 and gecko driver 0.19.0

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Webdriver {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub


        System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        //System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver.exe");
        //WebDriver driver = new ChromeDriver();

        driver.get("https://maps.mapmyindia.com");

        Thread.sleep(2000);
        driver.findElement(By.id("auto")).sendKeys("TCS");

        Thread.sleep(2000);
        driver.findElement(By.id("auto_geo")).click();

When i run this code on eclipse luna there is an error: Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities

like image 447
shivam Avatar asked Jan 05 '18 04:01

shivam


3 Answers

new FirefoxDriver(DesiredCapabilities caps); 

is deprecated, use

FirefoxOptions options = new FirefoxOptions();
options.setCapability("marionette", false);
WebDriver webDriver = new FirefoxDriver(options);

and you are good to go

like image 182
Alexander Oreshin Avatar answered Jan 15 '23 16:01

Alexander Oreshin


Another possible cause is the outdated Firefox version.

I upgraded the version and it works fine!

I could open the browser only setting options.setCapability("marionette", true);, then in the open window I upgraded through the "About Firefox" dialog. Then you have to remove the line about marionette.

Probably the one I had was only going to work with marionette while we are trying to use it with geckodriver, which has a different protocol. Anyone who knows more than me can confirm or deny!

like image 40
caesarsol Avatar answered Jan 15 '23 15:01

caesarsol


SessionNotCreatedException

SessionNotCreatedException extends WebDriverException and is a RuntimeException which indicates that a session could not be created.

Possible Causes :

The possible causes of a new session not getting created are as follows :

  • Compatibility issues between JDK, Selenium, WebDriver and Web Browser versions.
  • Accessing the same port number by GeckoDriver or Marionette by the new session which previous session have't released yet.
  • Lack of access to CPU
  • Lack of Physical Memory
  • Lack of Swap Memory
  • Lack of Disc Cache
  • Lack of Network Bandwidth
  • Presence of OS chores within the system.

Code Block :

I don't see any coding issue in your code block as such.

Solution :

The simple solution would be as follows :

  • Always use the latest released version of JDK (Java SE 9.0.1), Selenium-Java client (v3.8.1), WebDriver variant (GeckoDriver v0.19.1) and Web Browser (Firefox Quantum Browser).
  • If the base version of the Web Browser is too old consider uninstalling the Browser through Revo Uninstaller and install a recent released GA version of Firefox Browser.
  • Always use quit() in the tearDown() method so that the webdriver and the webclient both are properly destroyed.
  • Clean the Project Workspace from your IDE before and after executing your Test Suite.
  • Clear the Browser Cache before and after the execution of your Tests.
  • Use CCleaner tool regularly to wipe away the OS chores.
  • Execute your Test.
like image 33
undetected Selenium Avatar answered Jan 15 '23 16:01

undetected Selenium