This error message…
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver'
.
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
…implies that your program was unable to locate the GeckoDriver within the mentioned directory.
As per your code trials you have used:
driver = webdriver.Firefox()
As you havn’t mentioned the absolute path of the GeckoDriver explicitly, your program searches for the GeckoDriver within the paths mentioned within your underlying Operating System PATH variable and unable to locate.
Solution
- As you are on Mac OS X download the latest geckodriver-v0.23.0-macos.tar.gz from mozilla/geckodriver, store it anywhere within your system.
-
In your program override the paths mentioned in your Operating System PATH variable through the argument
executable_path
as follows:from selenium import webdriver driver = webdriver.Firefox(executable_path="/path/to/geckodriver") print("Firefox Browser Invoked") driver.get('http://google.com/') driver.quit()