Selenium.common.exceptions.WebDriverException: Message: Connection refused

Here is my code:

from selenium import webdriver browser = webdriver.Firefox() browser.get('http://www.python.org') browser.close() 

It started the Firefox browser when I ran this script, but the page is blank, then an error message is displayed on the command line:

 Traceback (most recent call last): File "ad.py", line 3, in <module> browser = webdriver.Firefox() File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 76, in __init__ keep_alive=True) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__ self.start_session(desired_capabilities, browser_profile) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session response = self.execute(Command.NEW_SESSION, capabilities) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute self.error_handler.check_response(response) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: connection refused 

My python vesion is 2.7.3 and the selenium version is selenium-3.0.0.b3.egg-info

Please, how can I solve the problem ...

+12
source share
6 answers

Check the geckodriver.log file (should be in the same directory as the python file)

If it says Error: GDK_BACKEND does not match available displays , then install pyvirtualdisplay:

 pip install pyvirtualdisplay selenium 

You may also need xvfb:

 sudo apt-get install xvfb # Debian sudo yum install Xvfb # Fedora 

Then try adding this code:

 from pyvirtualdisplay import Display display = Display(visible=0, size=(800, 600)) display.start() 

Full example:

 from pyvirtualdisplay import Display from selenium import webdriver display = Display(visible=0, size=(800, 600)) display.start() browser = webdriver.Firefox() browser.get('http://www.python.org') browser.close() 
+17
source

As @kervvv mentioned, this problem is probably related to an older version of Firefox than geckodriver or geckodriver selenium and / or geckodriver . As far as I can tell, it should be noted that the specific error message from selenium is somewhat general or vague; thus, it does not explicitly show why the error occurs.

In case users ask for help using an older version of Firefox, including Extended Support Release (ESR), the following solution should work fine.

  1. Visit the Firefox download page to download the beta, Nightly, or Firefox developer version.
  2. Extract the package to an arbitrary location on your file system (anywhere)
  3. Specify FirefoxBinary in your code or script to indicate the downloaded location.

     from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary binary = FirefoxBinary('/home/username/firefox/firefox') driver = webdriver.Firefox(firefox_binary=binary) driver.get(url) 

This works for me in Gentoo, for example, where the version of geckodriver (0.20.0) and selenium (3.11.0) are the last available version, while Firefox (ESR) is in version 52.

+4
source

There was this problem. You must install DISPLAY. For me, the Xvfb framebuffer is running on the local computer at: 99.

 $ export DISPLAY=:99 
+3
source

There was the same problem. Thought it was a proxy or port (to no avail), but what solved my problem just updated Firefox. I ran 52.0.xxx and updated to 57.0.2 . Link here .

+3
source

This can be for various reasons.

  • Most likely, because the "latest" version of your geckodriver cannot communicate with your "slightly older" firefox.

  • The easiest way to fix this is to try different old versions of geckodriver. Run the following command to find the current version of your geckodriver

     geckodriver --version 
  • If it shows version as 19 or higher, follow these steps to use geckodriver version 17 (works 90% of the time)

    1. Your existing geckodriver can most often be placed in /usr/local/bin when you installed it earlier. First remove this by running sudo rm -r/usr/local/bin/geckodriver

    2. Download version 17 of geckodriver from this link . Move the downloaded file ( geckodriver-v0.17.0-arm7hf.tar.gz ) from the " Downloads " folder to the home directory.

    3. Unzip the file

       tar -xzvf geckodriver-v0.17.0-arm7hf.tar.gz 

      This will create a folder named "geckodriver" in your home directory

    4. Move / copy this extracted "geckodriver" to /usr/local/bin/

       sudo cp geckodriver /usr/local/bin/ 
    5. To run

       sudo reboot 

Restart your program now ...
It should work!

+2
source

The first thing to do: update Firefox and make sure you have the latest version of geckodriver installed ( https://github.com/mozilla/geckodriver/releases )

0
source

All Articles