ValueError:在 PATH、chromedriver_autoinstaller.install 上找不到 chrome 可执行文件

问题描述 投票:0回答:1

尝试使用 chromedriver_autoinstaller.install() 但收到 ValueError: No chromeexecutablefound on PATH

chromedriver_autoinstaller.install()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/e/reports_automation/venv/lib/python3.10/site-packages/chromedriver_autoinstaller/__init__.py", line 21, in install
    chromedriver_filepath = utils.download_chromedriver(path, no_ssl)
  File "/home/e/reports_automation/venv/lib/python3.10/site-packages/chromedriver_autoinstaller/utils.py", line 269, in download_chromedriver
    chrome_version = get_chrome_version()
  File "/home/e/reports_automation/venv/lib/python3.10/site-packages/chromedriver_autoinstaller/utils.py", line 140, in get_chrome_version
    path = get_linux_executable_path()
  File "/home/e/reports_automation/venv/lib/python3.10/site-packages/chromedriver_autoinstaller/utils.py", line 196, in get_linux_executable_path
    raise ValueError("No chrome executable found on PATH")
ValueError: No chrome executable found on PATH
python selenium-webdriver selenium-chromedriver
1个回答
0
投票

假设您的 Chrome 可执行文件位于操作系统的默认位置(或系统路径),这对于最新版本的 Selenium 来说应该足够了:

from selenium import webdriver

driver = webdriver.Chrome()
# ...
driver.quit()

但是,如果 Chrome 未位于默认位置,则必须指定它的位置。

例如,在下面的脚本中,用户提供 chromedriver 和 Chrome 二进制文件的位置:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path='./chromedriver.exe')
options = webdriver.ChromeOptions()
options.binary_location = "PATH_TO_BINARY.exe"
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
© www.soinside.com 2019 - 2024. All rights reserved.