我正在使用python和selenium,并从这个网站下载了用于我的windows计算机的chromedriver: http://chromedriver.storage.googleapis.com/index.html?path=2.15/

下载压缩文件后,我将压缩文件解压缩到我的下载文件夹中。然后我把可执行二进制文件(C:\Users\michael\Downloads\chromedriver_win32)的路径放到环境变量“path”中。

然而,当我运行以下代码:

  from selenium import webdriver

  driver = webdriver.Chrome()

... 我一直得到以下错误消息:

WebDriverException: Message: 'chromedriver' executable needs to be available in the path. Please look at     http://docs.seleniumhq.org/download/#thirdPartyDrivers and read up at http://code.google.com/p/selenium/wiki/ChromeDriver

但是-如上所述-可执行文件在路径中(!)…这是怎么回事?


当前回答

检查你的chrome驱动程序的路径,它可能不会从那里得到它。 只需复制粘贴驱动程序位置到代码。

其他回答

在Ubuntu上:

sudo apt install chromium-chromedriver

在Debian上:

sudo apt install chromium-driver

在macOS上安装Homebrew,然后执行

brew install --cask chromedriver

如果你正在使用机器人框架RIDE。然后你可以从官网下载Chromedriver.exe,并将这个。exe文件保存在C:\Python27\Scripts目录下。现在将此路径作为环境变量。C: \ Python27 \ \ chromedriver.exe的脚本。

重新启动计算机并再次运行相同的测试用例。你不会再遇到这样的问题了。

根据指令,当实例化webdriver时,你需要包含到ChromeDriver的路径。如铬。

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

适用于Linux和OSX

步骤1:下载chromedriver

# You can find more recent/older versions at http://chromedriver.storage.googleapis.com/
# Also make sure to pick the right driver, based on your Operating System
wget http://chromedriver.storage.googleapis.com/81.0.4044.69/chromedriver_mac64.zip

对于debian: wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip

步骤2:将chromedriver添加到/usr/local/bin目录

unzip chromedriver_mac64.zip
sudo mv chromedriver /usr/local/bin
sudo chown root:root /usr/local/bin/chromedriver
sudo chmod +x /usr/local/bin/chromedriver

您现在应该可以运行了

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://localhost:8000')

没有任何问题

我们必须添加路径字符串,以字符串前的字母r开头,对于原始字符串。我用这种方法进行了测试,它是有效的。

driver = webdriver.Chrome(r"C:/Users/michael/Downloads/chromedriver_win32/chromedriver.exe")