1

I am trying to open local files with Selenium. With the code below, Firefox is opening, but I have the error org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start..

    File gecko = new File("resources/geckodriver64.exe");
    System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());

    FirefoxOptions capabilities = new FirefoxOptions();
    capabilities.setCapability("marionette", false);
    WebDriver driver = new FirefoxDriver(capabilities);

    driver.get("file:///C:/example/myfile.pdf");

Can someone help me ? I couldn't find anything on the internet.

Azrix
  • 99
  • 1
  • 10

3 Answers3

1

We have now come to the part where you will see how you can use GeckoDriver to launch Firefox. You will first need to download GeckoDriver and then set its path. There are three different ways to use GeckoDriver with Selenium 3:

With setting system properties in the test With setting system properties by Environment Variable With setting up Browser Desired Capabilities

Download Gecko Driver:- 1- Gecko Driver different versions can be downloaded from Github. I suggest you to use the latest version.

Set System Properties for Gecko Driver:- Code to set the System properties is System.setProperty(“webdriver.gecko.driver”,”Path to geckodriver.exe”);

The complete program to launch the GeckoDriver will be like this:

package seleniumPrograms;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
public class Gecko_Driver {
public static void main(String[] args) throws InterruptedException {
    System.setProperty("webdriver.gecko.driver", "D:\\\\XXXX\\trunk\\Library\\drivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.toolsqa.com");

    Thread.sleep(5000);
    driver.quit();
}

}

  • Sure, thank you for your answer, but I already did that, check the 2 firsts lines of my code. Do you have a solution? – Azrix Sep 27 '18 at 06:46
0

Check Below answer. This is working solution on my machine. Please check your firefox version too.

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class geckodriver {
       public static void main(String[] args) throws InterruptedException {

             System.setProperty("webdriver.gecko.driver", "C:\\Users\\username\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
           Thread.sleep(5000);
//           DesiredCapabilities capabilities = DesiredCapabilities.firefox();
//            capabilities.setCapability("marionette", true);
//           
//           WebDriver driver = new FirefoxDriver(capabilities);

           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("http://www.google.com");

             Thread.sleep(5000);
             driver.quit();
}}
  • I tried, the result is the same, moreover `new FirefoxDriver(capabilities);` is deprecated. I have this log during the execution : INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()` – Azrix Sep 27 '18 at 10:08
  • Sure, here are logs : `sept. 27, 2018 12:29:09 PM org.openqa.selenium.remote.DesiredCapabilities firefox INFO: Using new FirefoxOptions() is preferred to DesiredCapabilities.firefox() Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start. Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z'` – Azrix Sep 27 '18 at 10:31
0

Can you try below code ?

    package seleniumPrograms;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    public class Gecko_Driver {

    public static void main(String[] args) throws InterruptedException {
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        WebDriver driver = new FirefoxDriver(capabilities);
        driver.get("http://www.google.com");

        Thread.sleep(5000);
        driver.quit();
    }
  • Thanks for your answer. But when I set marionette to true, I have the following error log : `Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities` – Azrix Oct 01 '18 at 11:24
  • @Azrix: I have modified my code. Can you please check ? –  Oct 01 '18 at 11:39
  • Sure, it tells me that it's better to use `new FirefoxOptions()`, and I still have the `SessionNotCreatedException` :/ – Azrix Oct 01 '18 at 11:42
  • Which version of firefox are you using? –  Oct 01 '18 at 12:03
  • 45.0, I don't have choice for that unfortunately – Azrix Oct 01 '18 at 12:23
  • This is the 0.22.0, i downloaded it on their GitHub [here](https://github.com/mozilla/geckodriver/releases) – Azrix Oct 01 '18 at 12:33
  • If I could find a solution for this version of firefox, it would be perfect, apart from that, it's good – Azrix Oct 02 '18 at 07:02
  • 1
    Or else try to change your selenium to version 2.53.1 and use below code: WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com"); Thread.sleep(5000); –  Oct 02 '18 at 07:06