Many chromedriver.exe are left hanging on Windows – Selenium

The Selenium WebDriver is closed, but the “chromedriver.exe” process is left hanging in the system. See figure :

chromedriver.exe

Problem

Here is the code, a simple WebDriver example to load a URL and exists, but the chromedriver.exe never get killed.

LoadWebPageExample.java

package com.mkyong.test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class LoadWebPageExample {
	public static void main(String[] args) {

		System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");

		ChromeOptions options = new ChromeOptions();
		options.addArguments("window-size=800,600");

		DesiredCapabilities capabilities = DesiredCapabilities.chrome();
		capabilities.setCapability(ChromeOptions.CAPABILITY, options);
		WebDriver driver = new ChromeDriver(capabilities);

		driver.get("http://google.com/");

		driver.close();

	}
}

Solution

This is a common mistake, to solve it, uses driver.quit() to end the automated test.

LoadWebPageExample.java

package com.mkyong.test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class LoadWebPageExample {
	public static void main(String[] args) {

		System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");

		ChromeOptions options = new ChromeOptions();
		options.addArguments("window-size=800,600");

		DesiredCapabilities capabilities = DesiredCapabilities.chrome();
		capabilities.setCapability(ChromeOptions.CAPABILITY, options);
		WebDriver driver = new ChromeDriver(capabilities);

		driver.get("http://google.com/");

		//driver.close();
		driver.quit();
	}
}

References

  1. Selenium – WebDriver Documentation
  2. Selenium – WebDriver JavaDoc
  3. Selenium – ChromeDriver
author image

mkyong

Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities. Read all published posts by

Comments

avatar
3000
newest oldest most voted
Flo Bayer
Guest
Flo Bayer

I always close the WebDrivers with driver.quit(), but there are still many ChromeDriver.exe in the process list.

Flo Bayer
Guest
Flo Bayer
Aneesh Mohan
Guest
Aneesh Mohan

Is there any powershell to kill all the chromedriver.exe which can be scheduled in the task scheduler???

K Robinson
Guest
K Robinson

Additionally if you use the DriverService interface, make sure to hold onto the service object and call stop() on it when you’re done with the driver (including in all exception conditions).