首页 > 解决方案 > Selenium Chrome 驱动程序显示未指定路径

问题描述

在运行任何硒代码时,它显示了这一点,我什至已将 chromedriver.exe 添加到我的目录中,但仍然出现此错误

  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Programming\Python\Projects\_Acoustify_\Scrapping bots\amazon_bot_2.py", line 4, in <module>
    driver = webdriver.Chrome()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

标签: pythonselenium

解决方案


在错误的最后一行,你必须chromedriver在 PATH 中。

如果要将其保留在项目目录中,请将路径添加chromedriver到您的webdriver调用中:

driver = webdriver.Chrome('/path/to/chromedriver')

推荐阅读