FileNotFoundError:[错误2]没有这样的文件或目录:'geckodriver':'geckodriver'与MAC OS中的GeckoDriver和Python

FileNotFoundError:[错误2]没有这样的文件或目录:'geckodriver':'geckodriver'与MAC OS中的GeckoDriver和Python

问题描述:

我创建了一个测试脚本以使用python在Eclipse中打开url,并收到以下错误:

I have created a test script to open a url in Eclipse using python and got the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 769, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1516, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver'

在处理上述异常期间,发生了另一个异常:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/Eclipse.app/Contents/MacOS/C:\EclipseWorkspaces\csse120/PythonSeleniumProject/src/PythonSeleniumModule.py", line 13, in <module>
    driver = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

我已经在堆栈溢出中阅读了有关的相关主题,但是没有一个能够回答/解决我的问题.

I have read in stack overflow about related topics but none of them answers/solves my problem.

请告知. 谢谢.

此错误消息...

FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver'
.
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

...表示您的程序无法在上述目录中找到 GeckoDriver .

...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()

由于您没有明确提及 GeckoDriver 绝对路径,因此您的程序会在路径中搜索 GeckoDriver 在您的基础 Operating System PATH 变量中提到并且无法找到.

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.

  • Mac OS X 上时,请从geckodriver-v0.23.0-macos.tar.gz . com/mozilla/geckodriver/releases"rel =" nofollow noreferrer> mozilla/geckodriver ,将其存储在系统中的任何位置.
  • 在程序中,通过参数 executable_path ,如下所示:

  • 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()