I set up a python code to run Selenium chromedriver.exe
. At the end of the run I have browser.close()
to close the instance. (browser = webdriver.Chrome()
) I believe it should release chromedriver.exe
from memory (I'm on Windows 7). However after each run there is one chromedriver.exe
instance remain in the memory. I hope there is a way I can write something in python to kill the chromedriver.exe
process. Obviously browser.close()
doesn't do the work. Thanks.

- 1,658
- 6
- 25
- 34

- 1,742
- 3
- 15
- 13
-
Bottom line...you have to kill the process somehow because the designers didn't build it in. All other ways might leave a process running and that is enough to warrant the kill. – Stephen G Jan 16 '15 at 17:27
28 Answers
per the Selenium API, you really should call browser.quit()
as this method will close all windows and kills the process. You should still use browser.quit()
.
However: At my workplace, we've noticed a huge problem when trying to execute chromedriver tests in the Java platform, where the chromedriver.exe actually still exists even after using browser.quit()
. To counter this, we created a batch file similar to this one below, that just forces closed the processes.
kill_chromedriver.bat
@echo off
rem just kills stray local chromedriver.exe instances.
rem useful if you are trying to clean your project, and your ide is complaining.
taskkill /im chromedriver.exe /f
Since chromedriver.exe is not a huge program and does not consume much memory, you shouldn't have to run this every time, but only when it presents a problem. For example when running Project->Clean in Eclipse.

- 28,221
- 15
- 85
- 110
-
5I cannot condone any answer that recommends killing processes without also mentioning the correct way to have those processes end normally. If you properly use the `quit` method, this should not be an issue. Force-killing the processes should only be a last resort, and your answer should reflect that. – JimEvans Jan 24 '14 at 11:50
-
18See the only issue with this, is that when you debug, and kill the execution - the process still remains. Even if you click the `X` it still remains. that's the **ONLY** reason for this batch file. Obviously `quit` is the way to go, however in my example, if you debug and stop execution - it never reaches the `quit`. – ddavison Jan 24 '14 at 14:50
-
But that's not the original question. Incidentally, this is why the .NET bindings (unlike, say, Java) open chromedriver.exe in a separate console window, so you can more easily see that the executable hasn't been shut down. – JimEvans Jan 24 '14 at 15:08
-
4i'm answering one of the questions: `I hope there is a way I can write something to kill the chromedriver.exe process.`. and yes, that is nice! Java doesn't do that – ddavison Jan 24 '14 at 15:09
-
@sircapsalot, thanks for the help. Ideally I wish to have something in python to shut it down. It seems `.quit()` doesn't work with chromedriver. If I have to resort to a batch file to `taskkill` chromedriver.exe, it's better I could run it with target PID. Since I have several chromedriver instances running at the same time, I want to kill the ones that have finishes its job. – KLI Jan 24 '14 at 15:16
-
in my answer, i state that it shouldn't present an issue other than your IDE complaining. Instead of killing the chromedriver processes in the middle, just kill them (if you have to) after your tests are finished – ddavison Jan 24 '14 at 15:18
-
3Depending on the test framework you use, you may also end up with phantom processes lying around if the tests fails in it's "setup". NUnit, for instance, will not call the TestFixtureTearDown method's if something in the TestFixtureSetup method's fail -> you create the browser, do some stuff, and *then* run the test. If something goes wrong when "you do some stuff", that's it, the process is staying there. – Arran Jan 24 '14 at 15:23
-
1If you use the DriverService interface, hold onto the service until you're done with the driver, and call DriverService.stop() as well. For me, the driver.quit() wasn't enough because I was using DriverService as well. – Kimball Robinson Jul 12 '16 at 16:19
-
The `/t` switch may be passed to `taskkill` in order to kill still running chrome subprocesses launched by chromedriver. – Stephan Feb 15 '18 at 21:52
browser.close()
will close only the current chrome window.
browser.quit()
should close all of the open windows, then exit webdriver.

- 8,961
- 3
- 38
- 47
-
14Thanks Richard. `browser.quit()` did close all open windows. But chromedriver.exe was not exited. And there was an error message ' InvalidURL: nonnumeric port: 'port''. – KLI Jan 24 '14 at 14:57
-
7OK. I tried `browser = webdriver.Firefox()`. Both `browser.close()` and `browser.quit()` would close all windows and release memory. However chromedriver wouldn't do the same. – KLI Jan 24 '14 at 15:05
-
Hey KLI. Here where I work, we've noticed the same exact things happening with chromedriver. This is why we have a batch file that we only run when we need to. chromedriver.exe is not a big process, but it does present a problem when we try to run Project->Clean for example – ddavison Jan 24 '14 at 15:10
Theoretically, calling browser.Quit will close all browser tabs and kill the process.
However, in my case I was not able to do that - since I running multiple tests in parallel, I didn't wanted to one test to close windows to others. Therefore, when my tests finish running, there are still many "chromedriver.exe" processes left running.
In order to overcome that, I wrote a simple cleanup code (C#):
Process[] chromeDriverProcesses = Process.GetProcessesByName("chromedriver");
foreach(var chromeDriverProcess in chromeDriverProcesses)
{
chromeDriverProcess.Kill();
}
-
It didn't help. The process is not killed when it's run under java – Denis Koreyba Aug 08 '16 at 15:29
-
@DenisKoreyba: I don't think that language of implementation should change behavior. On Windows OS, when process not held by anyone - you can kill it (even if it held, you can force and kill it). Are you trying to kill it after browser tab(s) closed? – Illidan Aug 09 '16 at 06:49
-
I'm using C# to do this, what I told bout java is that the process of TeamCity is run under it. Answering your question: yes, first I invoke Dispose() and then your code. – Denis Koreyba Aug 09 '16 at 07:18
-
This doesn't work on chrome driver, version 2.21 at least. The process is killed but the console window still displays, probably because some child process still persists. aalhanane's answer below works. – Silent Sojourner Feb 19 '18 at 22:49
-
I inserted abovementioned cleanup code into AssemblyCleanup section of the BaseDriverClass. How can I verify chromedriver.exe process were actually killed? – monkrus Jul 23 '19 at 16:43
//Calling close and then quit will kill the driver running process.
driver.close();
driver.quit();
-
1This didn't work for me. Calling driver.close(); will close the browser and set driver to null. And then there is no point of calling driver.quit(); as it will throw null exception. – user10398433 Jul 20 '20 at 21:37
-
the implementation has some changes in current selenium, you may not need quit() if process is killed. Make sure when you do that, your task manager should not have the browser process killed. – Shantonu Jul 23 '20 at 17:55
I had success when using driver.close()
before driver.quit()
. I was previously only using driver.quit()
.

- 3,887
- 1
- 23
- 34

- 529
- 4
- 11
It's kinda strange but it works for me. I had the similar issue, after some digging I found that there was still a UI action going on in the browser (URL loading or so), when I hit WebDriver.Quit()
.
The solution for me (altough very nasty) was to add a Sleep()
of 3 seconds before calling Quit().

- 407
- 1
- 9
- 18
-
3Thanks, this actually worked for me as well. I was using `WebDriver.Quit()` as well before, but sometimes it was leaving one chrome.exe process alive. Also I guess it is happening not on all operating systems. – Grengas Aug 03 '15 at 12:25
-
1This worked for me, too! It may make you feel a bit dirty but sometimes random Thread.Sleeps seem to be what the doctor ordered for UI tests. – Dan Csharpster May 22 '19 at 22:38
-
Same for me, close on its own or quit on its own left the driver process behind. Doing both cleaned up nicely. – Mark Ball May 30 '19 at 20:36
-
Great! This worked for me too. I added Task.Delay(TimeSpan.FromSeconds(3)); before calling driver.Quit() and it's closing all the chromedriver.exe files – user10398433 Jul 20 '20 at 21:49
This answer is how to properly dispose of the driver in C#
If you want to use a 'proper' mechanism that should be used to 'tidy up' after running ChromeDriver
you should use IWebDriver.Dispose();
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)
I usually implement IDisposable
on class that is dealing with IWebDriver
public class WebDriverController : IDisposable
{
public IWebDriver Driver;
public void Dispose()
{
this.Driver.Dispose();
}
}
and use it like:
using (var controller = new WebDriverController())
{
//code goes here
}
Hope this saves you some time

- 2,609
- 1
- 29
- 41

- 58,075
- 31
- 238
- 265
-
6I can confirm that there are still problems with this strategy! I am using Selenium WebDriver API .NET v3.13.1.0, my Chrome instance is up to date, and so is my Windows 10... I am using ChromeDriver (which implements IDisposable by inheritance) like this: `using (var driver = new ChromeDriver()) { //my code here }` Sometimes, not always, "something" (don't know what??) happens and `chromedriver.exe` is still unreleased according to my taskmanager. – Hauns TM Aug 03 '18 at 06:33
-
Kill Multiple Processes From the Command Line The first thing you’ll need to do is open up a command prompt, and then use the taskkill command with the following syntax:
taskkill /F /IM <processname.exe> /T
These parameters will forcibly kill any process matching the name of the executable that you specify. For instance, to kill all iexplore.exe processes, we’d use:
taskkill /F /IM iexplore.exe

- 614
- 1
- 6
- 12
Code c#
using System.Diagnostics;
using System.Management;
public void KillProcessAndChildren(string p_name)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher
("Select * From Win32_Process Where Name = '"+ p_name +"'");
ManagementObjectCollection moc = searcher.Get();
foreach (ManagementObject mo in moc)
{
try
{
KillProcessAndChildren(Convert.ToInt32(mo["ProcessID"]));
}
catch (ArgumentException)
{
break;
}
}
}
and this function
public void KillProcessAndChildren(int pid)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher
("Select * From Win32_Process Where ParentProcessID=" + pid);
ManagementObjectCollection moc = searcher.Get();
foreach (ManagementObject mo in moc)
{
try
{
KillProcessAndChildren(Convert.ToInt32(mo["ProcessID"]));
}
catch
{
break;
}
}
try
{
Process proc = Process.GetProcessById(pid);
proc.Kill();
}
catch (ArgumentException)
{
// Process already exited.
}
}
Calling
try
{
KillProcessAndChildren("chromedriver.exe");
}
catch
{
}
-
I have applied your code as a final cleansing. So far it seems to work. Good job! – Exzile Feb 25 '19 at 21:47
I had the same issue when running it in Python and I had to manually run 'killall' command to kill all processes. However when I implemented the driver using the Python context management protocol all processes were gone. It seems that Python interpreter does a really good job of cleaning things up.
Here is the implementation:
from selenium import webdriver
from selenium.webdriver import ChromeOptions
class Browser:
def __enter__(self):
self.options = webdriver.ChromeOptions()
self.options.add_argument('--headless=new')
self.options.add_argument('--no-sandbox')
self.driver = webdriver.Chrome(options=self.options)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.driver.close()
self.driver.quit()
And the usage:
with Browser() as browser:
browser.driver.get("http://www.example.com")
html = browser.driver.page_source
print(html)
So, you can use the following:
driver.close()
Close the browser (emulates hitting the close button)
driver.quit()
Quit the browser (emulates selecting the quit option)
driver.dispose()
Exit the browser (tries to close every tab, then quit)
However, if you are STILL running into issues with hanging instances (as I was), you might want to also kill the instance. In order to do that, you need the PID of the chrome instance.
import os
import signal
driver = webdriver.Chrome()
driver.get(('http://stackoverflow.com'))
def get_pid(passdriver):
chromepid = int(driver.service.process.pid)
return (chromepid)
def kill_chrome(thepid)
try:
os.kill(pid, signal.SIGTERM)
return 1
except:
return 0
print ("Loaded thing, now I'mah kill it!")
try:
driver.close()
driver.quit()
driver.dispose()
except:
pass
kill_chrome(chromepid)
If there's a chrome instance leftover after that, I'll eat my hat. :(

- 2,609
- 1
- 29
- 41

- 671
- 5
- 4
Python code:
try:
# do my automated tasks
except:
pass
finally:
driver.close()
driver.quit()

- 2,609
- 1
- 29
- 41

- 5,127
- 5
- 23
- 38
I know this is somewhat of an old question, but I thought I'd share what worked for me. I was having problems with Eclipse -- it wouldn't kill the processes, and so I had a bunch of phantom processes hanging around after testing the code using the Eclipse runner.
My solution was to run Eclipse as administrator. That fixed it for me. Seems that Windows wasn't permitting Eclipse to close the process it spawned.

- 1,339
- 1
- 24
- 29
-
This makes a lot of sense, but in my case it didn't work, `chromedriver.exe` stays visible among Task Manager processes no matter I start Eclipse as administrator or normal user. It's possible that in my case [this](http://stackoverflow.com/a/25738929/2814308) is the problem, because `chromedriver.exe` is 32 bit and my JRE is 64 bit. Eclipse Neon.1a (4.6.1), Windows 8.1 Pro 64 bit, Java 1.8.0_92-b14. – SantiBailors Dec 16 '16 at 10:28
I have looked at all the responses and tested them all. I pretty much compiled them all into one as a 'Safety closure'. This in C#
Note: you can change the param from IModule app to that of the actual driver.
public class WebDriverCleaner
{
public static void CloseWebDriver(IModule app)
{
try
{
if (app?.GetDriver() != null)
{
app.GetDriver().Close();
Thread.Sleep(3000); // Gives time for everything to close before quiting
app.GetDriver().Quit();
app.GetDriver().Dispose();
KillProcessAndChildren("chromedriver.exe"); // One more to make sure we get rid of them chromedrivers.
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
public static void KillProcessAndChildren(string p_name)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher
("Select * From Win32_Process Where Name = '" + p_name + "'");
ManagementObjectCollection moc = searcher.Get();
foreach (ManagementObject mo in moc)
{
try
{
KillProcessAndChildren(Convert.ToInt32(mo["ProcessID"]));
}
catch (ArgumentException)
{
break;
}
}
}
public static void KillProcessAndChildren(int pid)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid);
ManagementObjectCollection moc = searcher.Get();
foreach (ManagementObject mo in moc)
{
try
{
KillProcessAndChildren(Convert.ToInt32(mo["ProcessID"]));
}
catch
{
break;
}
}
try
{
Process proc = Process.GetProcessById(pid);
proc.Kill();
}
catch (ArgumentException)
{
// Process already exited.
}
}
}
This work with python for me
import os
os.system('cmd /k "taskkill /F /IM chromedriver.exe /T"')
os.system('cmd /k "taskkill /F /IM chrome.exe /T"')

- 2,609
- 1
- 29
- 41

- 21
- 2
I have this issue. I suspect its due to the version of Serenity BDD and Selenium. The chromedriver process never releases until the entire test suite finishes. There are only 97 tests, but having 97 processes eat up the memory of a server that hasn't much resources may be having an affect on the performance.
To address I did 2 things (this is specific to windows).
before each test (annotated with @Before) get the process id (PID) of the chromedriver process with:
List<Integer> pids = new ArrayList<Integer>(); String out; Process p = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq chromedriver.exe*\""); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((out = input.readLine()) != null) { String[] items = StringUtils.split(out, " "); if (items.length > 1 && StringUtils.isNumeric(items[1])) { pids.add(NumberUtils.toInt(items[1])); } }
after each test (annotated with @After) kill the PID with:
Runtime.getRuntime().exec("taskkill /F /PID " + pid);

- 41
- 2
I came here initially thinking surely this would have been answered/resolved but after reading all the answers I was a bit surprised no one tried to call all three methods together:
try
{
blah
}
catch
{
blah
}
finally
{
driver.Close(); // Close the chrome window
driver.Quit(); // Close the console app that was used to kick off the chrome window
driver.Dispose(); // Close the chromedriver.exe
}
I was only here to look for answers and didn't intend to provide one. So the above solution is based on my experience only. I was using chrome driver in a C# console app and I was able to clean up the lingering processes only after calling all three methods together.
For Ubuntu/Linux users: -
the command is either pkill
or killall
. pkill
is generally recommended, since on some systems, killall
will actually kill all processes.

- 1,776
- 3
- 20
- 29
I have used the below in nightwatch.js
in afterEach
hooks.
afterEach: function(browser, done) {
// performing an async operation
setTimeout(function() {
// finished async duties
done();
browser.closeWindow();
browser.end();
}, 200);
}
.closeWindow()
just simply closes the window. (But wont work for multiple windows opened).
Whereas .end()
ends all the remaining chrome processes.

- 2,609
- 1
- 29
- 41

- 1
- 1
I am using Protractor with directConnect. Disabling the "--no-sandbox" option fixed the issue for me.
// Capabilities to be passed to the webdriver instance.
capabilities: {
'directConnect': true,
'browserName': 'chrome',
chromeOptions: {
args: [
//"--headless",
//"--hide-scrollbars",
"--disable-software-rasterizer",
'--disable-dev-shm-usage',
//"--no-sandbox",
"incognito",
"--disable-gpu",
"--window-size=1920x1080"]
}
},

- 26
- 3
- Make Sure You get the Driver instance as Singleton
- then Apply at end
- driver.close()
- driver.quit()
Note: Now if we see task manager you will not find any driver or chrome process still hanging

- 449
- 4
- 9
Observed on version 3.141.0:
If you initialize your ChromeDriver with just ChromeOptions, quit() will not close out chromedriver.exe.
ChromeOptions chromeOptions = new ChromeOptions();
ChromeDriver driver = new ChromeDriver(chromeOptions);
// .. do stuff ..
driver.quit()
If you create and pass in a ChromeDriverService, quit() will close chromedriver.exe out correctly.
ChromeDriverService driverService = ChromeDriverService.CreateDefaultService();
ChromeOptions chromeOptions = new ChromeOptions();
ChromeDriver driver = new ChromeDriver(driverService, chromeOptions);
// .. do stuff ..
driver.quit()
-
This is the solution in java I believe. At least, it worked for me – Isabelle T. Apr 09 '20 at 22:49
I simply use in every test a method tearDown() as following and I have no problem at all.
@AfterTest
public void tearDown() {
driver.quit();
driver = null;
}
After quitting the driver instance clear it from the cache by driver = null
Hope the answer the question

- 11
- 1
There is another way which is working only for windows, but now it is deprecated. it works for previous selenium releases (it works on 3.11.0 version).
import org.openqa.selenium.os.WindowsUtils;
WindowsUtils.killByName("chromedriver.exe") // any process name you want

- 1,737
- 1
- 12
- 26
So, nothing worked for me. What I ended up doing was setting a unique ID on my addArguments to launch chromedriver, then when I want to quit I do something like this:
opts.addArguments(...args, 'custompid' + randomId());
Then to make sure it quits:
await this.driver.close()
await this.driver.quit()
spawn(`kill $(ps aux | grep ${RANDOM_PID_HERE} | grep -v "grep" | awk '{print $2}')`).on('error', e => { /* ignores when grep returns empty */ })
Ugly af, but it's the only thing that worked for my case.

- 2,031
- 5
- 23
- 34
just use this two ways:
- open console and run this:
taskkill /F /IM chromedriver.exe /T
for kill all chrome processes - after how your test is complete you should
driver.Dispose
, not Close and also not Quit, just Dispose it.
Good Luck.

- 1
Please try this tested codes:
ChromeDriverService driverService = ChromeDriverService.createDefaultService();
ChromeDriver chrome = new ChromeDriver(driverService, chromeOptions);
//
// code
//
//
chrome.close();
chrome.quit();
driverService.close();

- 1,532
- 14
- 25

- 1
- 1