Why can't selenium find the chrome driver?

余生长醉 提交于 2019-12-25 00:53:08

问题


I am following a tutorial on using selenium and python to make a web scrapper for twitter, and I ran into this error.

File "C:\Python34\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

I went to the website specified in the error and downloaded the driver. Then I added it to path by going to System Properties > Advanced > Environment Variables > Path > New and added the exe file to path. I tried again and i still got the error.


回答1:


Another way is download and uzip chromedriver and put 'chromedriver.exe' in C:\Python27\Scripts and then you need not to provide the path of driver, just

driver= webdriver.Chrome()

will work




回答2:


If you take a look to your exception:

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

At the indicated url, you can see the Getting started with ChromeDriver on Desktop (Windows, Mac, Linux).

Where there is written:

Any of these steps should do the trick:

  1. include the ChromeDriver location in your PATH environment variable
  2. (Java only) specify its location via the webdriver.chrome.driver system property (see sample below)
  3. (Python only) include the path to ChromeDriver when instantiating webdriver.Chrome (see sample below)

If you are not able to include your ChromeDriver location in your PATH environment variable, you could try with the third one option:

import time
from selenium import webdriver

driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path.
driver.get('http://www.google.com');


来源:https://stackoverflow.com/questions/46964509/why-cant-selenium-find-the-chrome-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!