【问题标题】:How to add chromedriver.exe to PATH?如何将 chromedriver.exe 添加到 PATH?
【发布时间】:2021-05-19 15:25:06
【问题描述】:

我已经安装了 webdriver 和 selenium。当我尝试运行代码以打开谷歌时,我收到此错误。我曾多次尝试将 .exe 添加到路径中,但它不起作用。

消息=消息:“chromedriver.exe”可执行文件需要在 PATH 中。请看https://sites.google.com/a/chromium.org/chromedriver/home

【问题讨论】:

标签: python selenium google-chrome webdriver


【解决方案1】:

现在您可以设置 chromedriver 进行自动升级:

pip install chromedriver-autoinstaller

代码:

from selenium import webdriver
import chromedriver_autoinstaller


chromedriver_autoinstaller.install()  # Check if the current version of chromedriver exists
                                      # and if it doesn't exist, download it automatically,
                                      # then add chromedriver to path

driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title

尝试以下代码进行手动设置:

driver = webdriver.Chrome("full path to chrome driver\\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("www.google.com")

【讨论】:

    【解决方案2】:

    在执行时安装驱动程序。
    使用webdriver_manager python 包会将其存储到缓存中并将确切路径传递给驱动程序。
    只有存在较新的驱动程序版本时才会下载。

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

    【讨论】:

      猜你喜欢
      • 2020-09-01
      • 1970-01-01
      • 2016-06-17
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      • 2021-10-03
      • 2014-03-10
      相关资源
      最近更新 更多