How to Kill IEDriver exe process running in background (Selenium webdriver)?

人走茶凉 提交于 2019-12-01 10:57:26

You can add the following code at the end of your test script to close the IE Driver. So there is no need of closing it manually.

try {
    Runtime.getRuntime().exec("taskkill /F /IM IEDriverServer.exe");
} catch (IOException e) {
    e.printStackTrace();
}

Else open notepad and paste the following code.

taskkill /F /IM IEDriverServer.exe

Save the file as closedriver.bat

Click on this batch file when u want to close the IE Driver.

Close browser:

try{
WebDriver driver = new InternetExplorerDriver();
.. write all the webdriver code here like driver.get, driver.findElement().click() etc. etc.
}
catch(Throwable webDriverException){
  if(webDriverException.getMessage().contains("org.openqa.selenium.WebDriverException: Error communicating with the remote browser. It may have died"){
      // Kill IEDriverServer.exe process
      // Using WebDriver WindowUtils utility 
      WindowsUtils.killByName("IEDriverServer.exe");

      // Or using JavaRunTime
     Runtime.getRuntime().exec("taskkill /F /IM IEDriverServer.exe")
  }

}

See if this helps!!!

AL Lopez

If you are using MS test, on [TestCleanup] or [ClassCleanup] add the following:

foreach(var process in Process.GetProcess("IEDriverServer"))
{
  process.Kill();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!