How to kill IEDriverServer.exe console window after running an InternetExplorerDriver Selenium test How to kill IEDriverServer.exe console window after running an InternetExplorerDriver Selenium test selenium selenium

How to kill IEDriverServer.exe console window after running an InternetExplorerDriver Selenium test


To complement the awser, some informations about the subject. There are 3 main methods that that you can use as you need:

.Close(): - This method is used to close the current open window. It closes the current open window on which driver has focus on.

.Quit(): - This method is used to destroy the instance of WebDriver. It closes all Browser Windows associated with that driver and safely ends the session. Quit() calls Dispose method to achieve this.

.Dispose(): - This method closes all Browser windows and safely ends the sessionemphasized text

In your case, as you need to kill the process, the best choice is use .Quit().

Sometimes you're unable to end the process when your selenium instance broke up, and the current and all next tests starts to fail, or even when you cancel a current debugging test suit. In this cases, you really need to kill the process.

As @Prateek saw, one of they is using Runtime.getRuntime(). In C#, the better way to do it is:

foreach (var proc in Process.GetProcessesByName("IEDriverServer")){    proc.Kill();}

You can use it in the constructor where you start your WebDriver (but before to start it!) or, if you're using some lib as NUnit, you can create a global OneTimeSetUp. A kind of method that runs only one time before all test.

Also, if you don't like to put code or create new methods to do this job, you can configure in yout main .csproj the pre-build and post-build to execute your cmd command. Whenever you will run your tests or build your project, it will kill the opened webdriver instance.

To configure it you will need:

  1. Right button in your .csproj and click in "Properties";

  2. Navigate to "Build Events";

  3. Paste the command taskkill /f /fi "pid gt 0" /im IEDriverServer.exe in pre-build textarea, post-build or in both.


There are two ways:

  1. As suggested in comments driver.quit() will do the job.

  2. But sometimes our test fails and the Driver keeps running. To avoid having multiple instances of drivers you can use: Runtime.getRuntime().exec("taskkill /T /F /IM IEDriverServer.exe");.

The benefit of using this command is that even if your script doesn't run completely it would still kill the driver.

You can use it in a number of places. For example:

  1. If you are using frameworks such as TestNG you can override onTestFailure().
  2. You can add it in the beginning of your test so that if there are any instances already open they'll be killed.
  3. Or you can add in other places such as catch block.


I think you should try this:

        InternetExplorerDriverService service = InternetExplorerDriverService.CreateDefaultService();        service.Start();        IWebDriver driver = new ThreadLocal<IWebDriver>(() => { return new InternetExplorerDriver(service); }).Value;        int pid = service.ProcessId;        // Do any automation you want with your driver...        driver.Quit(); // it calls Dispose        service.Dispose();        // And if you want to ensure... :-)        try { Process.GetProcessById(pid).Kill(); }        catch { }

Please, notice that it is suitable for Chrome, Firefox and other drives!