FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver' with GeckoDriver and Python in MAC OS

有些话、适合烂在心里 提交于 2019-11-29 16:27:18

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()
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!