OpenQA.Selenium.WebDriverException after Impersonation

Won’t fix Issue #10497256


Rico S.
Jan 11, 2017
This issue is public.
Reported by 1 person

Sign in to watch or report this issue.

Steps to reproduce

I am using WrapperImpersonationContext class to impersonate a new user to run my Selenium Scripts. In other words simulating Run IE as different user.

However, I get the following exception when I try to initiate my IWebDriver.

Exception thrown: ‘OpenQA.Selenium.WebDriverException’ in WebDriver.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="" Severity="Critical"><TraceIdentifier></TraceIdentifier><Description>Unhandled exception</Description><AppDomain>FIM_Selenium.vshost.exe</AppDomain><Exception><ExceptionType>OpenQA.Selenium.WebDriverException, WebDriver, Version=, Culture=neutral, PublicKeyToken=null</ExceptionType><Message>A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:20972/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.</Message><StackTrace> at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver…ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)

This is my code.

private void button1_Click(object sender, EventArgs e)

        using (WrapperImpersonationContext context = new WrapperImpersonationContext("MyDomain", "My Username", "My Password"))
            Console.WriteLine("Current user: " +WindowsIdentity.GetCurrent().Name);
            Console.WriteLine("Current user: " + WindowsIdentity.GetCurrent().Name);

            String IE_DRIVER_PATH;
            String url = "";

            if (Environment.Is64BitOperatingSystem)
                IE_DRIVER_PATH = @"C:\software\selenium\drivers\64\";
                IE_DRIVER_PATH = @"C:\software\selenium\drivers\32\";
            var options = new InternetExplorerOptions()
                InitialBrowserUrl = url,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                IgnoreZoomLevel = true

            IWebDriver driver = new InternetExplorerDriver(IE_DRIVER_PATH, options, TimeSpan.FromMinutes(1));
            Console.WriteLine("Current user: " + WindowsIdentity.GetCurrent().Name);


What am I doing wrong or what can I do to get this resolved?


0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Ibrahim O.”

      Changed Assigned To to “Brad E.”

      Changed Status to “Won’t fix”

    • Hello,

      Thank you for providing your feedback on IE11. We are not accepting feedback on Internet Explorer through this portal any longer (unless security related). We welcome any feedback you have on Microsoft Edge through this website.

      Best Wishes,
      The MS Edge Team

    You need to sign in to your Microsoft account to add a comment.

    Sign in