How to kill an IEDriver exe process in the background (Selenium webdriver)?

I am using selenium webdriver (for Internet Explorer). What he does is basically open a web page in Internet Explorer and really shape the submission.

How can I automatically kill internetexplorer.exe in the background?

+2
source share
3 answers

You can add the following code at the end of the test script to close the IE driver. Therefore, there is no need to close it manually.

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

Open notepad again and paste the following code.

taskkill /F /IM IEDriverServer.exe

Save the file as closedriver.bat

Click this batch file when you want to close the IE driver.

+6
source

:

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")
  }

}

, !!!

+1

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

foreach(var process in Process.GetProcess("IEDriverServer"))
{
  process.Kill();
}
0
source

All Articles