0

I'm unable to launch Firefox browser for the following scripts.

Script #1:

System.setProperty("webdriver.gecko.driver", "D:\\selenium\\Geckodriver\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);  
driver.close();

Script #2:

System.setProperty("webdriver.gecko.driver", "D:\\selenium\\Geckodriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");

My Firefox Version : 45.0.1
Selenium Jar Version : selenium-server-standalone-3.4.0
Gecko Driver Version : geckodriver-v0.20.1-win32

I'm getting the error message as mentioned below:

Exception in thread "main" org.openqa.selenium.WebDriverException: connection refused
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'SYNCGDC4098', ip: '172.26.59.52', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_151'
Driver info: driver.version: FirefoxDriver
remote stacktrace: 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$22(ProtocolHandshake.java:365)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:368)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
    at seleniumtips.BasicScript.openApp(BasicScript.java:10)
    at seleniumtips.BasicScript.main(BasicScript.java:18)

What did I do wrong?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Karunagara
  • 389
  • 1
  • 8
  • 30

3 Answers3

0

As you can see from the geckodriver releases, the current latest version of the geckodriver is v0.20.1. You should use this one with the current latest version of the Firefox browser.

In addition, you are using an old version of selenium (from here, the current latest one is the 3.12.0).

You need to update your firefox browser and the selenium standalone server.

If you want (are forced) to use the oldest one (45.0.1), you should use the related geckodriver.

Davide Patti
  • 3,391
  • 2
  • 18
  • 20
0

You can upgrade the Selenium and geckodriver respectively as told by @Davide Patti. However in your script1 this line : WebDriver driver = new FirefoxDriver(capabilities); will not be supported by Selenium 3.12.0 since it' been deprecated.

Code that you can try out :

FirefoxOptions foptions =  new FirefoxOptions();  
foptions.setCapability("marionette", true);  
WebDriver driver = new FirefoxDriver(foptions);
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

This error message...

Exception in thread "main" org.openqa.selenium.WebDriverException: connection refused
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'

...implies that WebDriverException was raised as the driver failed to start its internal server to communicate with the Java Client.

To keep things simple, as you are using Selenium Java Client v3.4.0 and Firefox v45.0.1 you need to use compatible GeckoDriver binary.

Geckodriver 0.16 is strongly recommended

  • So you have to bump down GeckoDriver binary version to 0.16.0.

  • Now as you would be using Selenium Java Client v3.4.0, GeckoDriver v0.16.0 with Firefox v45.0.1 you have to use the System.setProperty() line to pass the Key webdriver.gecko.driver along with the Value as the absolute path of the GeckoDriver binary and finally through an instance of DesiredCapabilities class set the capability marionatte to false and then use merge() method from MutableCapabilities class to merge the capability into an instance of FirefoxOptions instance to initiate the Firefox Browser as follows :

    System.setProperty("webdriver.gecko.driver", "C:/path/to/geckodriver.exe");
    DesiredCapabilities dc = new DesiredCapabilities();
    dc.setCapability("marionatte", false);
    FirefoxOptions opt = new FirefoxOptions();
    opt.merge(dc);
    FirefoxDriver driver =  new FirefoxDriver(opt);
    driver.get("https://stackoverflow.com");
    System.out.println("Application opened");
    System.out.println("Page Title is : "+driver.getTitle());
    driver.quit();
    

You can find similar discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352