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

前端 未结 3 629
情话喂你
情话喂你 2021-01-15 01:35

I\'m using selenium webdriver(for Internet Explorer). What it does it basically opens a webpage in internet explorer and does form submitting.

How can I kill intern

相关标签:
3条回答
  • 2021-01-15 01:47

    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!!!

    0 讨论(0)
  • 2021-01-15 02:01

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

    foreach(var process in Process.GetProcess("IEDriverServer"))
    {
      process.Kill();
    }
    
    0 讨论(0)
  • 2021-01-15 02:03

    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.

    0 讨论(0)
提交回复
热议问题