WebDriverException: Message: Connection Disconnected
I am using selenium with geckodriver, trying to get html page. Below is the code I am using
from pyvirtualdisplay import Display
from selenium import webdriver
#start the virtual display
display = Display(visible=0, size=(800, 600))
display.start()
# start the browser. Using firefox.
browser = webdriver.Firefox()
browser.get('https://www.google.com')
print browser.title
browser.quit()
display.stop()
When I execute it with python, I get the following error.
Traceback (most recent call last):
File "test.py", line 9, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused
I turned to geckodriver.log
.
1500842848329 geckodriver INFO geckodriver 0.18.0
1500842848362 geckodriver INFO Listening on 127.0.0.1:45467
1500842849526 geckodriver::marionette INFO Starting browser /usr/bin/firefox with args ["-marionette"]
I'm not sure where to look next. Any hints?
Update1: It seems that when I used power reset in VPS the script started working. I researched it further and remembered that from the previous firefox attempts that I had to kill, there were four outstanding processes. I don't know enough about the internal processing in Linux to fully understand this. Is geckodriver confusing?
source to share
I had this problem too ... even on a machine with an X server and a fully functional KDE environment. It turns out there are strict version requirements when using geckodriver and Firefox. I was running an older version of Firefox with the latest geckodriver. After I downloaded the version mentioned in the release notes (and specified the path to that firefox binary in my webdriver declaration) it worked fine:
driver = webdriver.Firefox(firefox_binary='/path/to/latest/firefox/binary')
source to share