Error message:
‘chromedriver’ executable needs to be in PATH
I was trying to code a script using selenium in pycharm, however the error above occured. I have already linked my selenium to pycharm as seen here (fresh and up to date).
I am new to selenium, isn’t chromedriver in the folder «selenium.»
If it isn’t, where can I find it and add it to the path?
By the way, I tried typing «chromedriver» in cmd, however, it wasn’t recognized as an internal or external command.
error shown below:
Traceback (most recent call last):
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
PermissionError: [WinError 5] Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/sebastian/PycharmProjects/web/bot.py", line 10, in <module>
browser = webdriver.Chrome("C:/Users/sebastian/desktop/selenium-3.0.1")
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'selenium-3.0.1' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x01EDEAF0>>
Traceback (most recent call last):
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Troubleshooting missing path to driver executable.
Historically, this is the most common error beginning Selenium users get
when trying to run code for the first time:
The path to the driver executable must
be set by the webdriver.chrome.driver system property;
for more information, see https://chromedriver.chromium.org/.
The latest version can be downloaded from https://chromedriver.chromium.org/downloads
The executable chromedriver needs to be available in the path.
The file geckodriver does not exist. The driver can be downloaded at https://github.com/mozilla/geckodriver/releases»
Unable to locate the chromedriver executable;
Likely cause
Through WebDriver, Selenium supports all major browsers.
In order to drive the requested browser, Selenium needs to
send commands to it via an executable driver.
This error means the necessary driver could not be
found by any of the means Selenium attempts to use.
Possible solutions
There are several ways to ensure Selenium gets the driver it needs.
Use the latest version of Selenium
As of Selenium 4.6, Selenium downloads the correct driver for you.
You shouldn’t need to do anything. If you are using the latest version
of Selenium and you are getting an error,
please turn on logging
and file a bug report with that information.
If you want to read more information about how Selenium manages driver downloads for you,
you can read about the Selenium Manager.
Use the PATH
environment variable
This option first requires manually downloading the driver.
This is a flexible option to change location of drivers without having to update your code,
and will work on multiple machines without requiring that each machine put the
drivers in the same place.
You can either place the drivers in a directory that is already listed in PATH
,
or you can place them in a directory and add it to PATH
.
To see what directories are already on PATH
, open a Terminal and execute:
If the location to your driver is not already in a directory listed,
you can add a new directory to PATH:
echo 'export PATH=$PATH:/path/to/driver' >> ~/.bash_profile
source ~/.bash_profile
You can test if it has been added correctly by checking the version of the driver:
To see what directories are already on PATH
, open a Terminal and execute:
If the location to your driver is not already in a directory listed,
you can add a new directory to PATH:
echo 'export PATH=$PATH:/path/to/driver' >> ~/.zshenv
source ~/.zshenv
You can test if it has been added correctly by checking the version of the driver:
To see what directories are already on PATH
, open a Command Prompt and execute:
If the location to your driver is not already in a directory listed,
you can add a new directory to PATH:
setx PATH "%PATH%;C:\WebDriver\bin"
You can test if it has been added correctly by checking the version of the driver:
chromedriver.exe --version
Specify the location of the driver
If you cannot upgrade to the latest version of Selenium, you
do not want Selenium to download drivers for you, and you can’t figure
out the environment variables, you can specify the location of the driver in the Service object.
You first need to download the desired driver,
then create an instance of the applicable Service
class and
set the path.
Specifying the location in the code itself has the advantage of not needing
to figure out Environment Variables on your system, but has the drawback of
making the code less flexible.
Driver management libraries
Before Selenium managed drivers itself, other projects were created to
do so for you.
If you can’t use Selenium Manager because you are using
an older version of Selenium (please upgrade),
or need an advanced feature not yet implemented by Selenium Manager,
you might try one of these tools to keep your drivers automatically updated:
- WebDriverManager (Java)
- WebDriver Manager (Python)
- WebDriver Manager Package (.NET)
- webdrivers gem (Ruby)
Download the driver
Browser | Supported OS | Maintained by | Download | Issue Tracker |
---|---|---|---|---|
Chromium/Chrome | Windows/macOS/Linux | Downloads | Issues | |
Firefox | Windows/macOS/Linux | Mozilla | Downloads | Issues |
Edge | Windows/macOS/Linux | Microsoft | Downloads | Issues |
Internet Explorer | Windows | Selenium Project | Downloads | Issues |
Safari | macOS High Sierra and newer | Apple | Built in | Issues |
Note: The Opera driver no longer works with the latest functionality of Selenium and is currently officially unsupported.
Support the Selenium Project
Want to support the Selenium project? Learn more or view the full list of sponsors.
Error message:
‘chromedriver’ executable needs to be in PATH
I was trying to code a script using selenium in pycharm, however the error above occured. I have already linked my selenium to pycharm as seen here (fresh and up to date).
I am new to selenium, isn’t chromedriver in the folder «selenium.»
If it isn’t, where can I find it and add it to the path?
By the way, I tried typing «chromedriver» in cmd, however, it wasn’t recognized as an internal or external command.
error shown below:
Traceback (most recent call last):
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
PermissionError: [WinError 5] Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/sebastian/PycharmProjects/web/bot.py", line 10, in <module>
browser = webdriver.Chrome("C:/Users/sebastian/desktop/selenium-3.0.1")
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'selenium-3.0.1' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x01EDEAF0>>
Traceback (most recent call last):
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
This page documents how to start using ChromeDriver for testing your website on desktop (Windows/Mac/Linux).
You can also read Getting Started with Android or Getting Started with ChromeOS
ChromeDriver is a separate executable that Selenium WebDriver uses to control Chrome. It is maintained by the Chromium team with help from WebDriver contributors. If you are unfamiliar with Selenium WebDriver, you should check out the Selenium site.
Follow these steps to setup your tests for running with ChromeDriver:
-
Ensure Chromium/Google Chrome is installed in a recognized location
ChromeDriver expects you to have Chrome installed in the default location for your platform. You can also force ChromeDriver to use a custom location by setting a special capability.
-
Download the ChromeDriver binary for your platform under the downloads section of this site
-
Help WebDriver find the downloaded ChromeDriver executable
Any of these steps should do the trick:
-
-
include the ChromeDriver location in your PATH environment variable
-
(Java only) specify its location via the webdriver.chrome.driver system property (see sample below)
-
(Python only) include the path to ChromeDriver when instantiating webdriver.Chrome (see sample below)
-
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import org.junit.Test;
public class GettingStarted {
@Test
public void testGoogleSearch() throws InterruptedException {
// Optional. If not specified, WebDriver searches the PATH for chromedriver. System.setProperty(«webdriver.chrome.driver», «/path/to/chromedriver»); WebDriver driver = new ChromeDriver();
driver.get(«http://www.google.com/»);
Thread.sleep(5000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name(«q»));
searchBox.sendKeys(«ChromeDriver»);
searchBox.submit();
Thread.sleep(5000); // Let the user actually see something!
driver.quit();
}
}
import time
from selenium import webdriver
driver = webdriver.Chrome(‘/path/to/chromedriver’) # Optional argument, if not specified will search path.
driver.get(‘http://www.google.com/’);
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name(‘q’)
search_box.send_keys(‘ChromeDriver’)
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
Controlling ChromeDriver’s lifetime
Controlling ChromeDriver’s lifetime
The ChromeDriver class starts the ChromeDriver server process at creation and terminates it when quit is called. This can waste a significant amount of time for large test suites where a ChromeDriver instance is created per test. There are two options to remedy this:
1. Use the ChromeDriverService. This is available for most languages and allows you to start/stop the ChromeDriver server yourself. See here for a Java example (with JUnit 4):
import java.io.*;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.remote.*;
public class GettingStartedWithService {
private static ChromeDriverService service;
private WebDriver driver;
@BeforeClass
public static void createAndStartService() throws IOException {
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(«/path/to/chromedriver»))
.usingAnyFreePort()
.build();
service.start();
}
@AfterClass
public static void stopService() {
service.stop();
}
@Before
public void createDriver() {
driver = new RemoteWebDriver(service.getUrl(), new ChromeOptions());
}
@After public void quitDriver() {
driver.quit();
}
@Test
public void testGoogleSearch() {
driver.get(«http://www.google.com»);
// rest of the test…
}
}
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(‘/path/to/chromedriver’)
service.start()
driver = webdriver.Remote(service.service_url)
driver.get(‘http://www.google.com/’);
time.sleep(5) # Let the user actually see something!
driver.quit()
2. Start the ChromeDriver server separately before running your tests, and connect to it using the Remote WebDriver.
Terminal:
$ ./chromedriver
Starting ChromeDriver 76.0.3809.68 (…) on port 9515
…
import java.net.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.remote.*;
public class GettingStartedRemote {
public static void main(String[] args) throws MalformedURLException {
WebDriver driver = new RemoteWebDriver(
new URL(«http://127.0.0.1:9515»),
new ChromeOptions());
driver.get(«http://www.google.com»);
driver.quit();
}
}
[web scraping, scraping, automation, browser, chromedriver, install chromedriver, selenium]
Web Scraping Using an Automated Browser
Sometimes when we scrape the web, we need to automate our computer to open a web browser to gather information from each page. This is especially true when the site we want to scrape has content that is loaded dynamically with javascript.
We will install one package to help us here: ChromeDriver. Below we show two different ways of installing it.
Install ChromeDriver
In order to install ChromeDriver, make sure you have already installed:
-
Google Chrome.
-
Selenium: by typing in the command
pip install selenium
.- Alternatively, open Anaconda Prompt (Windows) or the Terminal (Mac), type the command
conda install selenium
, and agree to whatever the package manager wants to install or update (usually by pressingy
to confirm your choice).
- Alternatively, open Anaconda Prompt (Windows) or the Terminal (Mac), type the command
-
Webdriver Manager for Python: by typing in the command
pip install webdriver_manager
Once you have obtained these packages, you can now install ChromeDriver as follows:
# Make selenium and chromedriver work for Untappd.com
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
#driver = webdriver.Chrome()
driver = webdriver.Chrome(ChromeDriverManager().install())
url = "https://untappd.com/"
driver.get(url)
Manually Installing ChromeDriver
If for any reason the prior did not work or if you simply prefer installing ChromeDriver manually, follow the operating-system-specific steps below.
Windows Users
Watch our YouTube video, in which we walk you through the setup on Windows.
- Install Google Chrome from here.
- Download the windows version of Chromedriver from here.
- Extract the contents from the zip file, and extract them into a new directory under
C:\chromedriver
. If you do not have admin rights, you can put the file also in another folder, for exampleC:\Program Files\chromedriver
, orC:\Users\[your-username]\chromedriver
. It does not matter where exactly the file will be put, as long as you remember where it is (it’s not a good idea though to leave it in your downloads folder). - Make sure that the chromedriver.exe file is directly under the PATH you specified, i.e. under
C:\chromedriver
(or an alternative path). If your zip unpacker created a new folder with a different name inside your specified folder, move the .exe file to that path. - Add the directory
C:\chromedriver
(or whichever directory you chose above) to your PATH as described before (for instructions, see below) - If this went successfully, open a terminal/command prompt, and enter
chromedriver --version
, you should get output that looks likeChromeDriver [version number]
Warning
Making chromedriver
available via the PATH settings on Windows.
We need to update our PATH settings; these settings are a set of directories that Windows uses to “look up” software to startup.
-
Open the settings for environment variables
- Right-click on Computer.
- Go to “Properties” and select the tab “Advanced System settings”.
- Choose “Environment Variables”
-
Alternatively, type “environment variable” (Dutch: omgevingsvariabelen) in your Windows 10 search menu, and press Enter.
-
Select
Path
from the list of user variables. ChooseEdit
. -
Windows 7 and 8 machines:
If you chose your installation directory to beC:\chromedriver
during your installation (i.e., you did use the default directory), copy and paste the following string without spaces at the start or end:`;C:\chromedriver`
-
Windows 10 machines:
-
Click
New
and paste the following string:C:\chromedriver
-
Click on
OK
as often as needed.
-
Mac Users
Let’s install Homebrew first!
Make sure your Homebrew
package is up-to-date. To do so, open a terminal and enter
If that returns an error, Homebrew
is not installed.
- To install Homebrew, open a terminal and paste the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- To verify that Homebrew installed correctly, enter the following into your terminal
…and you should see the following output
Your system is ready to brew
Sometimes, brew doctor
returns some warnings. While it’s advisable to fix them (eventually), you typically don’t have to do it to get started with Chromedriver — so just try to continue from here.
Let’s proceed to installing Chromedriver
-
We assume you have Google Chrome installed. If not, do this first, please.
-
Install
chromedriver
via Homebrew:
brew install chromedriver --cask
- Verify your install, by entering the following in your terminal. The expected output is
ChromeDriver XX
Linux Users
- Open a terminal session
- Install Google Chrome for Debian/Ubuntu by pasting the following and then pressing
Return
sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
sudo apt-get install -f
- Install
xvfb
so chrome can run ‘headless’ by pasting the following and then pressingReturn
sudo apt-get install xvfb
- Install Chromedriver by pasting the following and then pressing
Return
:
sudo apt-get install unzip
wget -N https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
- Your install worked, you should get
ChromeDriver XX
returned if the installation was successful