zgg6a
zgg6a

Reputation: 289

browser = webdriver.Chrome() not working

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

Answers (6)

divija572
divija572

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

Mahesh Kumar Sharma
Mahesh Kumar Sharma

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

undetected Selenium
undetected Selenium

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

Zoette
Zoette

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

Ali Azam
Ali Azam

Reputation: 2115

For windows:

  1. Check you have installed latest version of chrome browser
  2. If not, install latest version of chrome
  3. download the latest(or appropriate) version of chromedriver from here
  4. 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

Amit Tripathi
Amit Tripathi

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

Related Questions