Reputation: 289
I am getting started with Selenium for python and have this:
from selenium import webdriver
browser = webdriver.Chrome()
However it gives this error:
Traceback (most recent call last):
File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-
packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\Bradley
Jo\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in
__init__
restore_signals, start_new_session)
File "C:\Users\Bradley
Jo\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 997, 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 "C:\Users\Bradley Jo\Desktop\Project\app.py", line 3, in
<module>
browser = webdriver.Chrome()
File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-
packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
self.service.start()
File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\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
[Finished in 1.0s]
Anyone have any idea how to fix this? Thanks
Upvotes: 2
Views: 31133
Reputation: 1
You may try to put the chromedriver in the same folder as your program. That worked for me. Then this code in the python document should suffice.
from selenium import webdriver
driver = webdriver.Chrome()
Upvotes: 0
Reputation: 11
You just need to pass the Chromedriver.exe
's path in below command
from selenium import webdriver
webdriver.Chrome(Chromedriver.exe's path)
Then it starts working
Upvotes: 1
Reputation: 193128
The error says it all as follows :
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
You need to override any other existing paths and pass the absolute path of the chromedriver
binary as an argument while initializing the webdriver
instance as follows :
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
Upvotes: 0
Reputation: 1281
My guess is that the problem comes from your path that contains a space ("Bradley Jo"):
C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py
You may try to put your webdriver elsewhere.
Upvotes: 0
Reputation: 2115
For windows:
- Check you have installed latest version of chrome browser
- If not, install latest version of chrome
- download the latest(or appropriate) version of chromedriver from here
- Paste the
chromedriver.exe
file in"<Install Dir>/Python27/Scripts"
Folder.
The below code should work now:
from selenium import webdriver
driver = webdriver.Chrome()
Upvotes: 3
Reputation: 7261
From the error message:
'chromedriver' executable needs to be in PATH.
It's clear that you need to pass the path of Chrome web driver in webdriver.Chrome
driver_path = "/Users/amit/Downloads/chromedriver"
driver = webdriver.Chrome(driver_path)
Upvotes: 1