Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
hello i try too work with selenium on python but chrome driver give me an error
my code :
from selenium import webdriver
driver = webdriver.Chrome(executable_path = 'chromedriver.exe')

error :
Traceback (most recent call last):
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

    self.service.start()
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home  

PS D:\codes>


           > & C:/Users/eskandarijoon/AppData/Local/Programs/Python/Python39/python.exe d:/codes/slnm/main.py
Traceback (most recent call last):
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

  File "d:\codes\slnm\main.py", line 3, in <module>
    driver = webdriver.Chrome(executable_path = r'D:\codes\slnm(1)\chromedriver.exe')
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home  

PS D:\codes> & C:/Users/eskandarijoon/AppData/Local/Programs/Python/Python39/python.exe d:/codes/slnm/main.py
Traceback (most recent call last):
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

  File "d:\codes\slnm\main.py", line 3, in <module>
    driver = webdriver.Chrome(executable_path = r'D:\codes\slnm(1)\chromedriver.exe')
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home  

PS D:\codes> & C:/Users/eskandarijoon/AppData/Local/Programs/Python/Python39/python.exe d:/codes/slnm/main.py
Traceback (most recent call last):
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

  File "d:\codes\slnm\main.py", line 2, in <module>
    driver = webdriver.Chrome(executable_path = 'chromedriver.exe')
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home  

PS D:\codes> & C:/Users/eskandarijoon/AppData/Local/Programs/Python/Python39/python.exe d:/codes/slnm/main.py
Traceback (most recent call last):
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
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 "d:\codes\slnm\main.py", line 2, in <module>
    driver = webdriver.Chrome(executable_path = 'chromedriver.exe')
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\eskandarijoon\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home  


What I have tried:

from selenium import webdriver
driver = webdriver.Chrome(executable_path = 'chromedriver.exe')
Posted
Updated 23-Apr-21 20:03pm

Read the messages: some of them are very significant.
FileNotFoundError: [WinError 2] The system cannot find the file specified

selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
So follow the link, and see exactly what it says ...
 
Share this answer
 
这个解决方案确实有效,但由于本人时常粗心大意,因此提供一个无脑的解决方案。
不是自己编写的代码的话,有一种可能——自己的浏览器驱动与代码中的驱动并不一致。
因此修改代码中的浏览器驱动即可。
weather_web = webdriver.Chrome()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900