When I am trying to close the chrome browser using driver.quit() and driver.close(), browser is getting closed but chromedriver.exe process is not getting closed. How can we remove these processes while we are closing the browser. I am trying in java.
Yeah, it can be a general issue as browsers (especially Chrome) don't always like closing their driver processes.
You can put the below in the onFinish all tests method which kills them:
String systemType = System.getProperty("os.name").toLowerCase();
if (systemType.contains("win")) {
try {
// Selenium drivers don't always close properly, kill them
System.out.println("Close one or more driver exe files");
Runtime.getRuntime().exec("taskkill /f /im chromedriver.exe");
Runtime.getRuntime().exec("taskkill /f /im operadriver.exe");
Runtime.getRuntime().exec("taskkill /f /im geckodriver.exe");
Runtime.getRuntime().exec("taskkill /f /im IEDriverServer.exe");
} catch (IOException e) {
System.out.println("Failed to close one or more driver exe files");
}
}
-
How can we kill processes which are abandoned ? Without disturbing the running processes – sri Oct 25 at 4:49
I do something similar (albeit in C#):
using System.Diagnostics;
namespace <Redacted for privacy>.Helper_Classes
{
public class KillDriverObjects
{
public void KillOpenChromeDrivers()
{
Process[] killChrome = Process.GetProcessesByName("chromedriver.exe");
foreach (var process in killChrome)
{
process.Kill();
}
}
public void KillOpenIEDrivers()
{
Process[] killInternetExplorer = Process.GetProcessesByName("iexplore.exe");
foreach (var process in killInternetExplorer)
{
process.Kill();
}
}
}
}
NOTE: I would use this approach very sparingly as it will kill all of the processes, not just the one you are targeting.