John Reilly
John Reilly

Reputation: 6269

IE 11 - webdriver.Quit() does not work

I'm brand new to Selenium and appear to be falling at the first hurdle. Whilst I can close browser windows quite happily in Firefox, the same does not work in IE.

See example test below which leaves me with one open IE window each time it is run:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;

namespace TestingTesting123
{
    [TestClass]
    public class About
    {
        IWebDriver _ieDriver;
        IWebDriver _ffDriver;

        [TestInitialize]
        public void Startup()
        {
            _ffDriver = new FirefoxDriver(); // Closes
            _ieDriver = new InternetExplorerDriver(); // Doesn't
        }

        [TestMethod]
        public void Go_to_bbc()
        {
            _ffDriver.Url = "http://news.bbc.co.uk";
            _ieDriver.Url = "http://news.bbc.co.uk";
        }

        [TestCleanup]
        public void Cleanup()
        {
            _ffDriver.Quit();
            _ieDriver.Quit();
        }
    }
}

There's a similar problem reported here for Java - I seem to have the same issue but C#.

I'm using IE 11 on Windows 8.1. I can workaround this issue by doing this:

using System.Diagnostics;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;

namespace TestingTesting123Workaround
{
    [TestClass]
    public class About
    {
        IWebDriver _ieDriver;
        IWebDriver _ffDriver;
        int[] _startupIEProcessIds;

        [TestInitialize]
        public void Startup()
        {
            _startupIEProcessIds = Process.GetProcessesByName("iexplore")
                                          .Select(x => x.Id).ToArray();

            _ffDriver = new FirefoxDriver();
            _ieDriver = new InternetExplorerDriver();
        }

        [TestMethod]
        public void Go_to_bbc()
        {
            _ffDriver.Url = "http://news.bbc.co.uk";
            _ieDriver.Url = "http://news.bbc.co.uk";
        }

        [TestCleanup]
        public void Cleanup()
        {
            _ffDriver.Quit();
            _ieDriver.Quit();

            foreach (var ieDriver in Process.GetProcessesByName("IEDriverServer"))
                ieDriver.Kill();
            foreach (var ie in Process.GetProcessesByName("iexplore")
                                      .Where(x => !_startupIEProcessIds.Contains(x.Id)))
                ie.Kill(); // Typing that was oddly therapeutic
        }
    }
}

However, this seems very heavy handed and not best practice. Any thoughts?

Upvotes: 4

Views: 1296

Answers (1)

greatkilt
greatkilt

Reputation: 11

You might want to give this a try since quit/close should have worked. It could be that IE has a bug currently that will be fixed at a later point but in the meantime this might be helpful. I have had similar issues with the chrome driver and firefox in the past.

Internet Explorer 11 does not close after Selenium Test

Upvotes: 1

Related Questions