Error message: “'chromedriver' executable

2019-01-01 13:10发布

I am using selenium with python and have downloaded the chromedriver for my windows computer from this site: http://chromedriver.storage.googleapis.com/index.html?path=2.15/

After downloading the zip file, I unpacked the zip file to my downloads folder. Then I put the path to the executable binary (C:\Users\michael\Downloads\chromedriver_win32) into the Environment Variable "Path".

However, when I run the following code:

  from selenium import webdriver

  driver = webdriver.Chrome()

... I keep getting the following error message:

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

But - as explained above - the executable is(!) in the path ... what is going on here?

11条回答
孤独总比滥情好
2楼-- · 2019-01-01 13:41

We have to add path string, begin with the letter r before the string, for raw string. I tested this way, and it works.

driver = webdriver.Chrome(r"C:/Users/michael/Downloads/chromedriver_win32/chromedriver.exe")
查看更多
只若初见
3楼-- · 2019-01-01 13:45

According to the instruction, you need to include the path to ChromeDriver when instantiating webdriver.Chrome eg.:

driver = webdriver.Chrome('/path/to/chromedriver')
查看更多
孤独寂梦人
4楼-- · 2019-01-01 13:47

(for Mac users) I have the same problem but i solved by this simple way: You have to put your chromedriver.exe in the same folder to your executed script and than in pyhton write this instruction :

import os

os.environ["PATH"] += os.pathsep + r'X:/your/folder/script/'

查看更多
查无此人
5楼-- · 2019-01-01 13:51

I see the discussions still talk about the old way of setting up chromedriver by downloading the binary and configuring path manually.

This can be done automaticatically using webdriver-manager

pip install webdriver-manager

Now the above code in the question will work simply with below change,

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

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

The same can be used to set Firefox, Edge and ie binaries

查看更多
余生无你
6楼-- · 2019-01-01 13:56

If you are working with robot framework RIDE. Then you can download Chromedriver.exe from its official website and keep this .exe file in C:\Python27\Scripts directory. Now mention this path as your environment variable eg. C:\Python27\Scripts\chromedriver.exe.

Restart your computer and run same test case again. You will not get this problem again.

查看更多
登录 后发表回答