Puzzled
Puzzled

Reputation: 69

Java throws Exception :Selenium 3.4.0,Gecko driver 16.01,FF 53.01

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");

Upvotes: 0

Views: 347

Answers (3)

undetected Selenium
undetected Selenium

Reputation: 193108

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.

Upvotes: 1

santhosh kumar
santhosh kumar

Reputation: 2019

Initiate FirefoxDriver instead of marionette driver.

WebDriver driver = new FirefoxDriver(capabilities);

Hope this helps you. Thanks.

Upvotes: 0

Prateeksha Chauhan
Prateeksha Chauhan

Reputation: 68

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

Upvotes: 0

Related Questions