IE 11 browser not closing in Selenium C#

636 views Asked by At

When trying with IE11 driver. It does not close with driver.Close() and driver.Quit.

Below is my basic code for launching and closing.

//Declaring IE driver
IWebDriver driver = new InternetExplorerDriver();
//IWebDriver driver = new ChromeDriver();

//Navigate to test URL
driver.Navigate().GoToUrl("http://www.google.com");

//Close the browser
driver.Quit();
//driver.Close();
1

There are 1 answers

1
Isma On BEST ANSWER

Seems like a BUG in Selenium:

https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4288

https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/65

You could manually kill all processes:

InternetExplorerOptions options = new InternetExplorerOptions();
options.IgnoreZoomLevel = true;

IWebDriver driver = new InternetExplorerDriver(options);
driver.Navigate().GoToUrl("http://www.google.com");

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

foreach (var process in Process.GetProcessesByName("IExplore"))
{
    process.Kill();
}

I know, it is an ugly workaround and it will close all Internet Explorer windows currently running but at least it will clean up resources if you need to run this automatically.