The selenium geckodriver executable using Python must be in PATH

I'm a new programmer. I started to use Python about two months ago. Now I'm studying Sweigart's "automatically writing boring things in Python text". I am using IDLE and have installed selenium module and Firefox browser. Whenever I try to run the webdriver function, I get the following information:

from selenium import webdriver
browser = webdriver.Firefox()

Exception: -

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0DA1080>>
Traceback (most recent call last):
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\", line 163, in __del__
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\", line 135, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0E08128>>
Traceback (most recent call last):
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\", line 163, in __del__
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\", line 135, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Traceback (most recent call last):
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\", line 64, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Python\Python35\lib\", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Python\Python35\lib\", line 1224, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#11>", line 1, in <module>
    browser = webdriver.Firefox()
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\firefox\", line 135, in __init__
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\", line 71, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

I think I need to set the path for geckodriver, but I'm not sure how, so who can tell me what to do?

#1 building

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable must be in PATH.

First, you need to download the latest executable geckodriver from here to run the latest Firefox with selenium.

In fact, the Selenium client binding attempts to locate the geckodriver executable from the system PATH. You need to add the directory containing the executable to the system PATH.

  • On Unix systems, if you are using a bash compatible shell, you can attach it to the system's search path by doing the following:

    export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step
  • On Windows, you will need to update the Path system variable to Manual or Order will be Add the full directory PATH to the executable geckodriver (don't forget to reboot the system after adding the executable geckodriver to the system PATH takes effect). The principle is the same as Unix.

Now you can run the code as follows:-

from selenium import webdriver

browser = webdriver.Firefox()

selenium.common.exceptions.WebDriverException: Message: expected browser binary location, but binary location cannot be found in default location, 'moz: Firefox options. Binary' is not provided, and binary flag is not set on command line

The exception clearly indicates that Firefox was installed in another location when Selenium tried to find Firefox and started from the default location, but it was not found. You need to provide a binary location where Firefox is explicitly installed to start Firefox, as follows:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('path/to/installed firefox binary')
browser = webdriver.Firefox(firefox_binary=binary)

#2 building

This step has been solved for me on ubuntu firefox 50.

  1. download geckodriver

  2. Copy geckodriver to / usr / local / bin

You don't need to add

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/usr/bin/firefox'
browser = webdriver.Firefox(capabilities=firefox_capabilities)

#3 building

Unfortunately, none of the books published on Selenium / Python, nor most of Google's comments on this issue, clearly explain the path logic of setting on the MAC (all Windows!!!!!). youtube users have all set the path "after" (in my opinion, a cheap way out!). So for your Mac users, edit the bash path file using the following command:

>$touch ~ /. bash_profile; open ~ /. bash_profile

Then add a PATH similar to the following. ... * "set PATH PATH for geckodriver =" / usr / bin / geckodriver: ${PATH} "export PATH

Set PATH for Selenium firefox

PATH = "~ / users / yournamepath / venvpythoninterpreter / lib / python2.7 / site packages / selenium / webdriver / Firefox /: ${PATH}" export PATH

Set the PATH of the executable on the Firefox driver

PATH = "/ user / your PATH / venvpythoninterpreter / lib / python2.7 / site packages / selenium / webdriver / common / service. Py: ${PATH}" export PATH*

It works for me. I'm worried about when the Selenium Windows community can start playing real games and get us Mac users to join their own club memberships.

#4 building

@saurabh's answer solves this problem, but does not explain why using Python to automate boring work does not include these steps.

This is because the book is based on selenium 2.x, and the series of Firefox drivers do not require the gecko driver. When developing selenium, the gecko interface used to drive the browser is not available.

selenium 2.x Series Latest edition Is 2.53.6 (see for example This answer For easier viewing of versions).

Version 2.53.6 page There was no mention of geckos. But starting with version 3.0.2, documentation Clearly pointed out You need to install the gecko driver.

If, after upgrading (or installing on a new system), previously (or on an old system) running good software no longer works, and you are in a hurry, do the following to fix the selenium version in virtualenv

pip install selenium==2.53.6

But, of course, the long-term solution developed is to set up the new virtualenv with the latest version of Selenium, install the gecko driver, and test that everything is still going as expected. But major version bumps may introduce other API changes not covered in the book, so you may want to stick with older Selenium until you have enough confidence that you can resolve any differences between Selenium 2 and Selenium 3 APIs.

#5 building

I actually found that you can use the latest gecko driver without having to put it in the system path. I am currently using

Firefox 50.1.0

Python 3.5.2

Selenium 3.0.2

Windows 10

I'm running virtuareenv (I use PyCharm for management, assuming it uses Pip to install everything)

In the following code, I can use the execute? Path parameter to use a specific path for geckodriver (I found this by looking at lib \ \ site packages \ \ selenium \ \ webdriver \ \ Firefox \ \ webdriver. Py). Note that I suspect that the order of parameters when calling webdriver is important, which is why execute? Path is at the end of my code (the second line on the far right)

You may also notice that I use a custom firefox profile to solve the sec? Error? Unknown? Issuer problem, which I run into if the site being tested has an untrusted certificate. see also How can I use Selenium to disable untrusted connection warnings for Firefox?

After investigation, it is found that the puppet driver is incomplete and still running, and there is no way to set various functions or profile options to eliminate or set certificates. As a result, it's easier to use a custom profile.

Anyway, this is the code about how to make the geckodriver work without a path:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True

#you probably don't need the next 3 lines they don't seem to work anyway
firefox_capabilities['handleAlerts'] = True
firefox_capabilities['acceptSslCerts'] = True
firefox_capabilities['acceptInsecureCerts'] = True

#In the next line I'm using a specific FireFox profile because
# I wanted to get around the sec_error_unknown_issuer problems with the new Firefox and Marionette driver
# I create a FireFox profile where I had already made an exception for the site I'm testing
# see

ffProfilePath = 'D:\Work\PyTestFramework\FirefoxSeleniumProfile'
profile = webdriver.FirefoxProfile(profile_directory=ffProfilePath)
geckoPath = 'D:\Work\PyTestFramework\geckodriver.exe'
browser = webdriver.Firefox(firefox_profile=profile, capabilities=firefox_capabilities, executable_path=geckoPath)

Keywords: Selenium Firefox Python Windows

Added by Dongowarrior on Fri, 14 Feb 2020 09:48:31 +0200