0

When run,java throws following exception: Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, version=, platform=A. Im using gecko driver 16.1.When I use gecko 14.01 its navigating till gmail page and then not able to find element even when I set implicit wait.

    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.MarionetteDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    public class login {
    public static void main(String[] args) {
        // Create a new instance of the Firefox driver
    System.setProperty("webdriver.gecko.driver","C:/Users/asdf/Desktop/selenium/gecko32/geckodriver.exe");
    DesiredCapabilities capabilities=DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    WebDriver driver = new MarionetteDriver(capabilities);
        //WebDriver driver = new FirefoxDriver();
        //  Wait For Page To Load
        // Put a Implicit wait, this means that any search for elements on the page
    driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        // Navigate to URL
    driver.get("https://mail.google.com/");
    driver.manage().window().maximize();
    //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        // gmail login
    driver.findElement(By.xpath("//*[@id='identifierId']")).sendKeys("username");
    driver.findElement(By.id("next")).click();
    driver.findElement(By.id("Passwd")).sendKeys("password");
Puzzled
  • 69
  • 6

3 Answers3

1

Here is the Answer to your Question:

SessionNotCreatedException can be observed for different reasons, such as Selenium-geckodriver version mismatch, dangling geckodriver instances and OS chores. I will suggest you to consider the following steps:

  1. From Task Manager kill all the dangling geckodriver instances manually/programatically. If possible restart your system. If needed, run the CCleaner to wipe away all the unwanted OS chores from your system.
  2. Download Selenium Standalone Server 3.4.0 or Selenium Client 3.4.0 from this page.
  3. Download geckodriver v.0.16.1 from this page.
  4. Ensure you have installed the latest stable GA version of Mozilla Firefox 53.0
  5. The MarionetteDriver implementation is discontinued, you can consider using the FirefoxDriver implementation.
  6. For a detailed discussion on MarionetteDriver and GeckoDriver you can consider having a look at this discussion.
  7. Here is your own code which executes well with some minor tweaks:

    package demo;
    
    import java.util.concurrent.TimeUnit;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    public class Q44351100_SessionNotCreatedException 
    {
        public static void main(String[] args) 
        {
            System.setProperty("webdriver.gecko.driver","C:/your_directory/geckodriver.exe");
            DesiredCapabilities capabilities=DesiredCapabilities.firefox();
            capabilities.setCapability("marionette", true);
            WebDriver driver = new FirefoxDriver(capabilities);
            driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
            driver.get("https://mail.google.com/");
            driver.manage().window().maximize();
            driver.findElement(By.xpath("//*[@id='identifierId']")).sendKeys("username");
        }
    }
    

Let me know if this Answers your Question.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hii!Thanks a lot for the detailed solution.I have done all,and I tried running your code.Its navigating till the gmail page,but not able to use send keys and send the username to the field. – Puzzled Jun 13 '17 at 14:31
0

Try to use latest versions of Firefox browser and gecko driver. Hope this helps

0

Initiate FirefoxDriver instead of marionette driver.

WebDriver driver = new FirefoxDriver(capabilities);

Hope this helps you. Thanks.

santhosh kumar
  • 1,981
  • 1
  • 9
  • 28
  • I did as you said .I got this exception :Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@545997b1, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@545997b1, – Puzzled Jun 04 '17 at 07:40
  • did you got any error message for this.... WebDriver driver = new FirefoxDriver();; – santhosh kumar Jun 04 '17 at 07:51
  • yes the same error.As everybody suggested im using latest selenium and gecko v0.16.01.But gecho 14 is working till login page.But its not able to use sendkeys – Puzzled Jun 04 '17 at 07:56
  • It works in my machine. I am sure that we need to use firefox driver instead of marionetter. I am using selenium 3.2, firefox 13 and gecko 0.14. – santhosh kumar Jun 04 '17 at 08:00
  • im using FF 53,selenium 3.4.0 and gecko v 0.16.1.I tried with your seuugestion too ,still showing the same error.Im using eclipse kepler with jdk 1.8.No errors seen on code – Puzzled Jun 04 '17 at 08:02
  • can you try reinstalling FF – santhosh kumar Jun 04 '17 at 08:04