我正在使用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

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


当前回答

适用于mac osx用户

    brew tap homebrew/cask
    brew cask install chromedriver

其他回答

测试后检查ChromeDriver是否已安装

chromedriver

你应该看到

Starting ChromeDriver version.number 
ChromeDriver was successful

检查ChromeDriver的路径

which chromedriver

在代码中使用Path

...
from selenium import webdriver

options = Options()
options.headless = True
options.add_argument('windows-size=1920x1080')

path   = '/usr/local/bin/chromedriver'
driver = webdriver.Chrome(path, options=options)

在最近的版本中,创建chromedriver的首选方式是使用服务。

手动设置路径,如下所示:

chromedriver_path = "path to your chromedriver executable>"

service = Service(chromedriver_path)
driver = webdriver.Chrome(service=service)

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

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

最好的方法是:

下载并解压chromedriver,并将'chromedriver.exe'放在C:\Python27\Scripts中,然后您不需要提供驱动程序的路径,只需

driver= webdriver.Chrome()

你已经完成了,不需要添加路径或任何东西

另一种方法是下载并解压chromedriver,并将'chromedriver.exe'放在C:\Program Files\Python38\Scripts中,然后你不需要提供驱动程序的路径,只需

司机= webdriver.Chrome ()