Getting Chrome to launch via Selenium
Asked Answered
D

8

21

I am having issues getting an instance of a Chrome browser from selenium in python. I'm using Windows 8. I have downloaded the chromedriver binary and added it to my path but I get the following error in Python:

selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.   

This error occurs for the following line:

driver = webdriver.Chrome(executable_path='path\to\chromedriver_win32_2.0')  
Delight answered 2/7, 2013 at 22:3 Comment(6)
Have you read this yet?Pickaback
Click on the work "this".Pickaback
Oh dear that was stupid, couldn't see the link. Sorry, but I read it and it has no info about where Chrome is expected to be installed for Windows 8.Delight
You need to download the chrome driver that is provided in the link, and make that available in the path.Benefactress
Thank you for your response but if you read the question, I did that already.Delight
Path is C:\Program Files (x86)\Java\jdk1.6.0_43\bin;%path%;C:\Python27;C:\Python27\Scripts;C:\Program Files\Java64\bin;C:\Users\HaranKumar\Downloads\chromedriver_win32_2.0 and in the line is: 'C:\Users\HaranKumar\Downloads\chromedriver_win32_2.0' Thanks for the help!Delight
E
32

Two ways to set it, you somehow mixed up.

  • Put the chromedriver.exe's path into PATH (on Windows), so your PATH setting is correct, but you need to call the default constructor.

    driver = webdriver.Chrome()

  • Specify the path in webdriver.Chrome(executable_path='some path'). Here you need the full path to the executable, not the directory.

    webdriver.Chrome(executable_path=r'C:\Users\HaranKumar\Downloads\chromedriver_win32_2.0\chromedriver.exe')

Choose either one you want.

Enrich answered 4/7, 2013 at 20:57 Comment(1)
for windows use double slash webdriver.Chrome(executable_path='C:\\drivers\\chromedriver.exe')Handcrafted
B
2

Assuming that your path is correct, make sure that you include the chromedriver itself: chromedriver.exe

Barmy answered 3/7, 2013 at 10:59 Comment(1)
Having the file in PATH wasn't enough for me. Put it to `Python\Scripts`.Brezhnev
W
2

I used the following and it worked! Thanks!

driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe')
#put your own path between the ''
Weaver answered 6/3, 2019 at 19:27 Comment(0)
M
0

Even if you have chromedriver.exe in the PATH, its necessary to have chromedriver.exe in the folder where your executable scripts are present(atleast so is the case when it comes to python scripts)

Midship answered 9/3, 2019 at 5:18 Comment(0)
S
0

for python(selenium) you will need:

from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options

then put your chromedriver.exe path in. the "r" is just to prevent it from detecting the \ and causing errors in python

PATH = r"C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
options = webdriver.ChromeOptions()

you can now order the driver to get websites

driver.get('http://www.google.com')
Synectics answered 22/12, 2020 at 17:4 Comment(0)
M
0

Update 2021 For Python

I got Selenium to open my default Chrome browser with my profile using this:

options.add_argument("--user-data-dir=C:\\Users\\Sams\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument('--profile-directory=Default')
  1. Go to: chrome://version/
  2. Look for your "Profile Path" profile path image
  3. Copy your Profile Path and replace "options.add_argument("--user-data-dir={YOUR PROFILE PATH}")"
  4. The second argument may also look different. Mine so happens to be "Default". For other it may be "Profile 1" or "Profile X" X being an incrementing number.
  5. Close all your Chrome browsers before running. Because the Chrome Driver cannot run an automated browser alongside the rest of your other tabs.

Here is my entire Selenium Config. Hopefully it helps someone.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.remote.webdriver import WebDriver
    

options = Options()
options.add_argument("--window-size=1920,1080")
options.add_argument("--log-level=3")
options.add_experimental_option('excludeSwitches', ['enable-logging'])


# The 2 arguments below will use your main browser. 
options.add_argument("--user-data-dir=C:\\Users\\Sams\\AppData\\Local\\Google\\Chrome\\User Data") # profile path (C)
options.add_argument('--profile-directory=Default')

options.headless = False # To show Chrome or not to show?
PATH = (r"C:\Users\Sams\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe") 

CHROMEDRIVER_PATH = PATH
driver = webdriver.Chrome(CHROMEDRIVER_PATH, options=options)
Mcghee answered 9/4, 2021 at 15:17 Comment(0)
P
0

I recently ran into this error and I found three main solutions for this chromedriver not in path error

  1. download a library that does it - webdriver_manager or chromedriver_autoinstaller both work
  2. add it to path in your program
  3. add chromedriver executable to your system PATH
Puffin answered 1/7, 2022 at 13:58 Comment(0)
W
-1

Update 2016

The following solution works for me, with WebDriver 3.0.1, Chrome Driver 2.25.426923, Window 7

    System.setProperty("webdriver.chrome.driver","D:\\workspace\\chromedriver.exe");
    WebDriver driver;
    driver = new ChromeDriver();

*Note:

Wintertide answered 7/12, 2016 at 3:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.