java.net.ConnectException: Connection refused: con

2020-03-26 05:59发布

问题:

I have downloaded the latest version of Firefox ie Quantum. For Selenium,earlier there was no need of downloading any executable for Firefox to open an URL but now it throws an error of setting property for GeckoDriver.

So, I downloaded the latest version of geckodriver-v0.20.1-arm7hf.tar.gz and put that in System.setProperty() so it has thrown an error of connection refusal.

So, I used the alternative for opening the URL on Chrome. Downloaded chromeExecutable and was able to open without any connection refusal.

Code snippet:-

System.setProperty("webdriver.gecko.driver", "C:\\XYZ\\XXXX\\Downloads\\geckodriver-v0.20.1-arm7hf.tar.gz");
    WebDriver driver=new FirefoxDriver();
    driver.get("https://google.com");

Console Error:

Caused by: java.net.ConnectException: Connection refused: connect

Can anyone please help to figure out the issue on Mozilla Firefox?

Thanks Mehak

回答1:

There aren't a lot of infos in your question, but I guess the following is an issue:

In

System.setProperty("webdriver.gecko.driver", "C:\XYZ\XXXX\Downloads\geckodriver-v0.20.1-arm7hf.tar.gz");

seems you are under a Windows OS (analyzing the path) but you are setting geckodriver-v0.20.1-arm7hf.tar.gz.

If you have a windows os, you should:

  1. Download from here the related version (geckodriver-v0.20.1-win64.zip or geckodriver-v0.20.1-win32.zip, it depends on your OS)
  2. Extract it and set, in the System.setProperty, the path to the extracted geckodriver.exe

Something like that:

System.setProperty("webdriver.gecko.driver", "C:\XYZ\XXXX\Downloads\geckodriver.exe");

If you are under another os, you should download the proper asset and do basically the same thing. If you hava a linux/mac os, you have to be sure that the extracted geckodriver is executable.



回答2:

As per the Best Practices you need to follow the points below:

  • Always use the latest released Selenium Java Client
  • Always use the latest released WebDriver binaries as per your relevant underlying OS from:

    • GeckoDriver : mozilla/geckodriver
    • ChromeDriver : ChromeDriver - WebDriver for Chrome
    • IEDriverServer : release.storage

As you are on Windows OS download either geckodriver-v0.20.1-win32.zip or geckodriver-v0.20.1-win64.zip and unzip for your usage.

  • Always keep your Browsers updated with the latest releases (Firefox, Chrome, IE)
  • In the System.setProperty() line the Value field should end with the name of the WebDriver variant as:

    • Windows :

      System.setProperty("webdriver.gecko.driver", "C:\\XYZ\\XXXX\\Downloads\\geckodriver.exe");
      
    • Linux :

      System.setProperty("webdriver.gecko.driver", "/opt/XYZ/XXXX/geckodriver");
      
    • MacOSX :

      System.setProperty("webdriver.gecko.driver", "/Users/XYZ/XXXX/geckodriver");