WebDriverException: Message: The browser appears to have exited before we could connect error with GeckoDriver Selenium and Python
This error message...
WebDriverException: Message: The browser appears to have exited before we could connect.
If you specified a log_file in the FirefoxBinary constructor, check it for details.
...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowser i.e. Firefox Browser session.You need to take care of a couple of things as follows:
- To set the
FirefoxBinary
you need to use theFirefoxOptions()
and instead of passing the absolute path of geckodriver binary, you have to pass the absolute path of the desired firefox binary. - As you are using GeckoDriver v0.21.0 you have to mandatorily use marionette so either keep it unchanged (by default
true
) or set marionette totrue
. Your own code with incorporating the minor changes will be:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
binary = r'C:\Program Files\Mozilla Firefox\firefox.exe'
options = Options()
options.set_headless(headless=True)
options.binary = binary
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = True #optional
driver = webdriver.Firefox(firefox_options=options, capabilities=cap, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.get("http://google.com/")
print ("Headless Firefox Initialized")
driver.quit()Console Output:
Headless Firefox Initialized
Here you can find a detailed discussion on Unable to find a matching set of capabilities with selenium 3.4.3, firefox 54.0 and gecko driver 0.17
The browser appears to have exited before we could connect. The output was: mkdir: cannot create directory
Cleared the Linux cache with the following two commands to resolve the issue:
Entered through putty ssh shell./usr/sbin/tmpwatch 1 /tmp
and/usr/sbin/tmpwatch 1 /var/tmp
How to fix the error upstream connect error or disconnect/reset before headers. reset reason: overflow in Selenium?
I've figured it out. The problem was in overloaded proxy
Related Topics
Dump to JSON Adds Additional Double Quotes and Escaping of Quotes
In-Place Type Conversion of a Numpy Array
How to Include Image Files in Django Templates
Is There a Numpy Builtin to Reject Outliers from a List
How to Solve Equations in Python
Why Can't You Add Attributes to Object in Python
How to Get Windows' Special Folders for Currently Logged-In User
What Does Model.Train() Do in Pytorch
Installing Pygraphviz on Windows 10 64-Bit, Python 3.6
How to Reinstall Python@2 from Homebrew
How to Limit the Maximum Value of a Numeric Field in a Django Model
How to Exit from Python Without Traceback
Wrapping Around on a List When List Index Is Out of Range