.NET Core, VS2019, and Selenium: IE Driver Doesn't Work (WebDriverException - HTTP request timeout)

1

UPDATE: This error only happens in Visual Studio 2019. I'm on 16.3.1 Community. Visual Studio 2017 works just fine and causes no issues. So it seems the crux of the issue lies in Visual Studio 2019 for some reason.

NOTE that no matter which IDE I build it in, dotnet run will fail just like VS2019 does. Only if I run the app within VS2017 does it work.

I cross-posted this to Microsoft via Visual Studio's built-in "Report a Problem" menu to attack this issue from multiple angles. I'll report back if/when they do anything (i.e. if they identify it as an issue with Visual Studio).


We've recently upgraded from .NET Framework to .NET Core. The application presently runs on .NET Core 2.2, but the same issues occur on .NET Core 3.0.

We run Selenium for UI testing, and for some reason, Internet Explorer's tests are quite wonky. The driver successfully launches the browser, but the first Navigate() call hangs indefinitely after it successfully performs navigation (never gets beyond that line of code). Here's the full stack trace:

OpenQA.Selenium.WebDriverException HResult=0x80131500

Message=The HTTP request to the remote WebDriver server for URL http://localhost:52211/session/9e1e828b-5e72-46d8-8012-6b29bfc2d854/url timed out after 10 seconds. Source=WebDriver

StackTrace: at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)

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.set_Url(String value)

at SandboxSelenium.Program.Main(String[] args) in C:\dev_sandbox\SandboxSelenium\SandboxSelenium\Program.cs:line 17

Inner Exception 1: WebException: The operation has timed out.

For simplicity, I created a brand new .NET Core Console App, and did nothing in Main except repeat the above step, and I recreated the issue.

Here are the whole csproj of the console app project, including package references:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
    <PackageReference Include="Selenium.WebDriver.IEDriver" Version="3.150.0" />
  </ItemGroup>
</Project>

And here's the code I'm calling:

using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using System;
using System.IO;
using System.Reflection;

namespace SandboxSelenium
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            string binPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // In .NET Core you have to tell Selenium where the EXE is.
            InternetExplorerOptions opts = new InternetExplorerOptions();
            using (var driver = new InternetExplorerDriver(binPath, opts, new TimeSpan(0, 0, 10)))
            {
                driver.Navigate().GoToUrl("https://example.com/"); // "Line 17" in above error. This line times out!
                IWebElement someTextbox = driver.FindElement(By.Id("SomeTextBox")); // Never gets here...
                someTextbox.SendKeys("abc123");
            }
        }
    }
}

NOTE: I only set the driver's command timeout to new TimeSpan(0, 0, 10) (10 seconds) in order to shorten the timeout from the default 60 seconds. It times out no matter how long or short the timeout is.

Also, it seems the server executable, IEDriverServer.exe, doesn't close either and is left hanging open after the crash.

I suspect that somehow Selenium is losing track of IE or something, since it seems to completely lose the browser itself. Not sure though. I have tried changing the PageLoadStrategy within InternetExplorerOptions for the driver, but that didn't help any. I have also tried using the 64bit NuGet package for the IE server driver, but that didn't change anything.

Any help is appreciated!

c#
selenium
internet-explorer
.net-core
visual-studio-2019
asked on Stack Overflow Sep 25, 2019 by Doctor Blue • edited Sep 26, 2019 by Doctor Blue

3 Answers

1

I faced the same issue and managed to solve this by running VS2019 as an administrator, the same worked for command line.

answered on Stack Overflow Jun 26, 2020 by T S
0

using (var driver = new InternetExplorerDriver(binPath, opts, new TimeSpan(0, 0, 10)))

The issue is relate to the InternetExplorerDriver setting (the above code). Please check the InternetExplorerDriver Constructor (String, InternetExplorerOptions, TimeSpan) method, we can see that the TimeSpan means the maximum amount of time to wait for each command. if the waiting time is over, it will show this error.

To prevent this error, you could try to extend the waiting time or remove this setting. Code as below:

        using (var driver = new InternetExplorerDriver(binPath, opts))
        {
            driver.Navigate().GoToUrl("https://www.bing.com/"); // "Line 17" in above error. This line times out!
            IWebElement someTextbox = driver.FindElement(By.Id("sb_form_q")); // Never gets here...
            someTextbox.SendKeys("abc123"); 
        }

Edit:

You could extend the waiting time, such as set it to 20 seconds.

Besides, when we use the SendKeys method to enter values into the textbox, it might be very slow and spend too much time. As a workaround, to decrease the spend time, we could use the IJavaScriptExecutor to execute the JavaScript script, and set the value.

Code as below:

        using (var driver = new InternetExplorerDriver(binPath, opts, new TimeSpan(0, 0, 20)))
        {
            driver.Navigate().GoToUrl("https://www.bing.com/"); // "Line 17" in above error. This line times out!
            //IWebElement someTextbox = driver.FindElement(By.Id("sb_form_q")); // Never gets here...
            //someTextbox.SendKeys("abc123");
            var element = driver.FindElementById("sb_form_q");

            var script = "document.getElementById('sb_form_q').value = 'webdriver';";
            IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;

            jse.ExecuteScript(script, element); 
            element.SendKeys(Keys.Enter); 
        }
answered on Stack Overflow Sep 26, 2019 by Zhi Lv • edited Sep 27, 2019 by Zhi Lv
0

Alright, it appears you are missing Microsoft Web driver. If you are using Windows OS I recommend go to <settings> --> select Update & Security, then to the left from the list choose For developers and finally click & select Developers mode and wait for the installation to complete and then run your project. I also recommend using EdgeDriver instead of InternetExploperDriver I hope this helps!

answered on Stack Overflow Nov 15, 2019 by Nazif Sahim

User contributions licensed under CC BY-SA 3.0