Saturday, August 25, 2018

How do I kill the Chrome driver processor by using selenium

In this post, we are going to explain how to kill chrome driver background process or release chromedriver.exe from memory with help of selenium webdriver.
As per the Selenium API, you really should call browser.quit() as this method will close all windows and kills the process. However most of time, we have noticed a huge problem when trying to execute chromedriver tests in the Java platform, where the chromedriver.exe actually still exists. To overcome such problem you need to apply below command in commands prompt.

How do I kill the Chrome driver processor by using selenium



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

It will kill the chrome driver background process, once you have entered above commands in command prompt. Refer the below screenshot :
How do I kill the Chrome driver processor by using selenium

You can directly run above command with help of java coding :

Method -1 :
Process[] chromeDriverProcesses = Process.GetProcessesByName("chromedriver");
foreach(var chromeDriverProcess in chromeDriverProcesses){
 chromeDriverProcess.Kill();
}

Method -2 :
Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe /T");

This will help you to release chromedriver.exe background process from the memory. Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.


3 comments:

  1. use driver.quit(); to kill the chromedriver.exe process...
    i know sometimes it wont work, will tell you what is the reason. You might have written below code.
    driver = null;
    driver.quit();
    but this is wrong. Use below code
    driver.quit();
    driver = null;
    the above code will work.

    ReplyDelete
  2. You want to avoid doing something like...
    Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe /T");
    ... if you are using tools like Jenkins to build and run tests in the background. By executing such a command, other tests running in parallel (in other projects) will be killed.

    ReplyDelete
  3. I want to run this command on Jenkins but is not working: bat 'taskkill /F /IM chromedriver.exe /T'... that .exe is in the directory, any idea?

    ReplyDelete