简体   繁体   English

如何杀死在后台运行的 IEDriver exe 进程(Selenium webdriver)?

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

I'm using selenium webdriver(for Internet Explorer).我正在使用 selenium webdriver(用于 Internet Explorer)。 What it does it basically opens a webpage in internet explorer and does form submitting.它所做的基本上是在 Internet Explorer 中打开一个网页并提交表单。

How can I kill internetexplorer.exe running in background Automatically ?如何自动终止在后台运行的 internetexplorer.exe?

You can add the following code at the end of your test script to close the IE Driver.您可以在测试脚本的末尾添加以下代码来关闭 IE 驱动程序。 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将文件另存为 closedriver.bat

Click on this batch file when u want to close the IE Driver.当您要关闭 IE 驱动程序时,请单击此批处理文件。

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!!!看看有没有帮助!!!

If you are using MS test, on [TestCleanup] or [ClassCleanup] add the following:如果您使用的是 MS 测试,请在[TestCleanup][ClassCleanup] 上添加以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM