如何将chromedriver.exe添加到PATH?

qyswt5oh  于 2023-06-19  发布在  Go
关注(0)|答案(2)|浏览(182)

我已经安装了webdriver和selenium。当我试图运行一个代码来打开谷歌,我得到这个错误。我已经多次尝试将.exe添加到路径中,但都不起作用。
消息=消息:“chromedriver.exe”可执行文件需要在PATH中。请参见https://sites.google.com/a/chromium.org/chromedriver/home

plicqrtu

plicqrtu1#

现在你可以设置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")
jucafojl

jucafojl2#

在执行时安装驱动程序。
使用webdriver_manager python包会将其存储到缓存中,并将确切的路径传递给驱动程序。

只有有更新版本的驱动程序才会下载

import selenium
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())

相关问题