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

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


当前回答

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

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

chromedriver_path = "path to your chromedriver executable>"

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

其他回答

在C:\Windows. exe中添加webdriver(chromedriver.exe或geckodriver.exe)。 这对我来说很管用

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

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

chromedriver_path = "path to your chromedriver executable>"

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

我遇到了和你一样的问题。 我使用PyCharm来编写程序,我认为问题在于PyCharm中的环境设置,而不是操作系统。 我通过转到脚本配置,然后手动编辑环境变量中的PATH解决了这个问题。 希望这对你有帮助!

正如Aphid在他的评论中提到的,如果你想手动完成,你必须只包括你的webdriver存储的目录,而不是可执行文件:

例子:

正确的:

路径=$PATH:/路径/到/网络驱动程序/文件夹

错误的:

PATH=$PATH:/path/to/webdriver/chromedriver.exe


Windows系统变量和CMD测试:

最好的方法是:

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

driver= webdriver.Chrome()

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