简体   繁体   中英

org.openqa.selenium.WebDriverException: connection refused while launching Firefox Browser 45.0.1 through Selenium v3.4.0 and geckodriver-v0.20.1

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?

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.

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

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question org.openqa.selenium.WebDriverException: connection refused while using Selenium Java and webdriver (linux headless with Xvfb) org.openqa.selenium.WebDriverException: [Exception… “Component not initialized” error using GeckoDriver and Tor browser with Selenium Java org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0 using GeckoDriver Firefox and Selenium error“ org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/” with GeckoDriver and Firefox org.openqa.selenium.WebDriverException: java.io.IOException: unexpected end of stream on Connection while invoking getCookies() with GeckoDriver Exception showing at the time of launching application - org.openqa.selenium.WebDriverException: Error While launching appium browser:- org.openqa.selenium.WebDriverException: ERROR running Appium command: Arguments to path.resolve must be strings org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start while initiating Chrome browser through Selenium org.openqa.selenium.WebDriverException: Browser failed to start, test in fluentlium Exception in thread “main” org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start after geckodriver upgradation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM