Chromedriver:“FileNotFoundError:[WinError 2]系统找不到指定的文件”错误

时间:2017-03-11 17:51:17

标签: python selenium-chromedriver

找了答案,却找不到任何答案。似乎坚持说它找不到指定的文件,然后检查PATH,但是即使这样也看不到:/我把目录放在路径中:http://imgur.com/a/ZP59w

计划:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com/")

错误:

Traceback (most recent call last):
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-       packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-  32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-     32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "H:\temp.py", line 2, in <module>
    driver = webdriver.Chrome()
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-   packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\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

如果有人能提供帮助,我们将不胜感激。

3 个答案:

答案 0 :(得分:0)

您可以尝试直接传递路径。

所以我的dekstop上有webdriver文件,所以:

webdriver.Chrome('C:/Users/adam/Desktop/chromedriver.exe')

您可以获取网络驱动程序here.

答案 1 :(得分:0)

我遇到了同样的问题,并使用Options方法解决了该问题。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\Program Files (x86)\Google\Chrome Dev\Application\chrome.exe"
driver = webdriver.Chrome(chrome_options=options, executable_path=r"C:\Program Files (x86)\Google\chromedriver.exe", )
driver.get("https://www.google.com/")

希望它可以解决您的问题。

答案 2 :(得分:0)

您可以使用以下内容:

from selenium import webdriver

browser = webdriver.Chrome(r"*your path here*")

如何获取路径? 如果在Windows系统上,转到Webdriver的提取位置,请按Shift键,然后选择Copy as Path

enter image description here