【问题标题】:chromedriver executable is in PATH but still getting errorchromedriver 可执行文件在 PATH 中,但仍然出现错误
【发布时间】:2021-06-15 05:23:51
【问题描述】:

我正在尝试使用 selenium,但出现错误

'chromedriver' executable needs to be in PATH.

但我知道它在 PATH 中。我的 exe 位于 C:\WebDriver\bin 中。它已添加到我的系统变量中 System variables image. 在命令提示符下运行chromedriver成功返回

Starting ChromeDriver 89.0.4389.23 (61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389@{#294}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

我已重新启动计算机。我尝试直接指定executable_path

driver = Chrome(executable_path=r"C:\WebDriver\bin\chromedriver.exe")

如果有人能理解这些logs,我使用 ProcessMonitor(过滤器:“路径包含 chromedriver”)

更新:

使用 webdriver-manager

from selenium import webdriver    
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())

给我错误

ValueError: Could not get version for Chrome with this command: google-chrome --version || google-chrome-stable --version

【问题讨论】:

标签: python selenium selenium-chromedriver process-monitor


【解决方案1】:

尝试使用 webdriver-manager 包:

pip install webdriver-manager

代码应如下所示:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())

模块自动下载驱动程序并将其存储在 selenium 的已知路径中。它将解决驱动程序路径的所有问题

【讨论】:

  • 使用这个我得到了错误:ValueError:无法使用此命令获取 Chrome 的版本:google-chrome --version || google-chrome-stable --version @Vova
  • @tape74 很有意思,好像有bug。
  • @tape74 它与 Firefox 兼容吗? from selenium import webdriver from webdriver_manager.firefox import GeckoDriverManager driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
  • 现在错误:SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line 我的 exe 在 C:\Program Files\Mozilla Firefox 中
  • 这里建议的解决方案stackoverflow.com/questions/65318382/… 但我不确定如何使用 webdriver-manager 的选项
【解决方案2】:

试试这个:

from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\WebDriver\bin\chromedriver.exe')

【讨论】:

    猜你喜欢
    • 2021-08-19
    • 1970-01-01
    • 2020-11-04
    • 2019-11-11
    • 2020-10-13
    • 2018-12-14
    • 2018-08-18
    • 2017-12-08
    • 1970-01-01
    相关资源
    最近更新 更多