【问题标题】:Chromedriver path not found? - Selenium - MacOS [duplicate]找不到 Chrome 驱动程序路径? - 硒 - MacOS [重复]
【发布时间】:2019-01-17 01:26:13
【问题描述】:

我已经在我的 MacOS 上下载了 Selenium 和 Chromedriver,但似乎无法在我的 IDLE Python Shell 上执行:

driver = webdriver.Chrome()

错误信息返回:

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 756, in __init__
restore_signals, start_new_session)
 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1499, in _execute_child
 raise child_exception_type(errno_num, err_msg, err_filename)
 FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'

  During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
  driver = webdriver.Chrome()
 File 
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site- 
packages/selenium/webdriver/chrome/webdriver.py", line 68, 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: 'chromedriver' 
 executable needs to be in PATH. Please see 
https://sites.google.com/a/chromium.org/chromedriver/home

我试图通过将 Chromedriver 放置在 usr/local/bin 中并将其放置在所附图像中的 selenium 文件夹中来将其设置在正确的路径中。但是,我不确定它是否在正确的位置,因为仍然会出现相同的错误。

我将如何解决这个问题?

非常感谢!

Where Webdriver is in my Folders

【问题讨论】:

    标签: python macos selenium selenium-chromedriver


    【解决方案1】:

    如您所知,主要错误是您的 chromedriver 可执行文件不在 PATH 中。在 Python 脚本中执行以下操作以指定 PATH:

    import sys
    path = '/path/to/your/chromedriver/executable'
    sys.path.append(path)
    
    # then continue your script
    

    据我所知,chromedriver 可执行文件不需要位于bin 目录中即可使用;你可以把它放在任何地方,只要你使用上面的代码指定它在哪里让你的程序找到它。

    【讨论】:

    • 我应该如何找到我的 Chromedriver 的位置?有什么办法可以在终端中调用它告诉我吗? - 抱歉,我是编程新手。
    • 您说您将 Chromedriver 放入 usr/local/bin/。在该文件夹中找到它并执行this。这是我见过的 Mac 用户最简单的方法(我不是 Mac 用户)
    猜你喜欢
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    • 2021-11-18
    • 2019-06-23
    • 2018-05-01
    • 2011-09-06
    相关资源
    最近更新 更多