【发布时间】:2019-03-28 08:38:05
【问题描述】:
我创建了一个测试脚本来使用 python 在 Eclipse 中打开一个 url,并得到以下错误:
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'
在处理上述异常的过程中,又发生了一个异常:
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.
我在堆栈溢出中阅读了有关相关主题的信息,但它们都没有回答/解决我的问题。
请指教。 谢谢。
【问题讨论】:
-
您是否阅读了错误消息:“消息:'geckodriver' 可执行文件需要在 PATH 中。”?
-
@KlausD。我可以知道哪个是正确的路径吗?我已将 geckodriver 可执行文件粘贴到 /usr/local/bin 和 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver 文件夹中
-
/usr/local/bin应该没问题。您可以通过在任何文件夹中简单地运行geckodriver从终端运行它吗? -
我已经运行了 geckodriver,它现在可以工作了。谢谢@Kla
标签: python macos selenium firefox geckodriver