selenium: [πŸ› Bug]: Testing WebView2 with automatic download of the Edge WebDriver no longer works

What happened?

We are using Selenium for testing a WebView2 instance from C# code. Originally we used the below code to create the EdgeDriver, as per Microsoft documentation:

using OpenQA.Selenium.Edge;

var options = new EdgeOptions { DebuggerAddress = "localhost:12345", UseWebView = true };
using var driver = new EdgeDriver(options);

This broke with (I believe) version 4.9, producing the following error:

Unhandled exception. OpenQA.Selenium.WebDriverException: Unable to locate driver with path: msedgedriver.exe, for more information on how to install drivers see https://www.selenium.dev/documentation/webdriver/getting_started/instal
l_drivers/
 ---> OpenQA.Selenium.WebDriverException: Invalid response from process (code 65): selenium-manager/windows/selenium-manager.exe  --browser "webview2" --output json
Invalid browser name: webview2
   at OpenQA.Selenium.SeleniumManager.RunCommand(String fileName, String arguments)
   at OpenQA.Selenium.SeleniumManager.DriverPath(DriverOptions options)
   at OpenQA.Selenium.DriverFinder.VerifyDriverServicePath(DriverService service, DriverOptions options)
   --- End of inner exception stack trace ---
   at OpenQA.Selenium.DriverFinder.VerifyDriverServicePath(DriverService service, DriverOptions options)
   at OpenQA.Selenium.Edge.EdgeDriverService.CreateDefaultService(EdgeOptions options)
   at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeOptions options)
   at Program.<Main>$(String[] args)

Assuming at the time that this was an intentional change, we removed the UseWebView property. Instead we added BrowserVersion to avoid Selenium picking up the version of the installed Edge browser (which might differ from the used WebView2 version for various reasons) as the basis for the Edge WebDriver version it downloads.

using OpenQA.Selenium.Edge;

var options = new EdgeOptions { DebuggerAddress = "localhost:12345", BrowserVersion = "116" };
using var driver = new EdgeDriver(options);

This however now also broke with Selenium 4.12.* and produces the following error:

Unhandled exception. OpenQA.Selenium.NoSuchDriverException: Unable to obtain MicrosoftEdge using Selenium Manager; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/error
s/driver_location
 ---> OpenQA.Selenium.WebDriverException: Error starting process: selenium-manager/windows/selenium-manager.exe  --browser "MicrosoftEdge" --output json
--browser-version 116
 ---> OpenQA.Selenium.WebDriverException: Selenium Manager process exited abnormally with 65 code: selenium-manager/windows/selenium-manager.exe  --brows
er "MicrosoftEdge" --output json --browser-version 116
Error Output >>


Standard Output >>
{
  "logs": [
    {
      "level": "ERROR",
      "timestamp": 1694621742,
      "message": "edge 116 cannot be downloaded"
    }
  ],
  "result": {
    "code": 65,
    "message": "edge 116 cannot be downloaded",
    "driver_path": "",
    "browser_path": ""
  }
}


   at OpenQA.Selenium.SeleniumManager.RunCommand(String fileName, String arguments)
   --- End of inner exception stack trace ---
   at OpenQA.Selenium.SeleniumManager.RunCommand(String fileName, String arguments)
   at OpenQA.Selenium.SeleniumManager.DriverPath(DriverOptions options)
   at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
   --- End of inner exception stack trace ---
   at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
   at OpenQA.Selenium.Chromium.ChromiumDriver.GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options)
   at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeOptions options)
   at Program.<Main>$(String[] args)

How can we reproduce the issue?

See code examples in the above description.

Relevant log output

According to the documentation there is no logger for .NET, so I am not sure where to get logs, aside from the exception stack traces above.

Operating System

Windows 10, Windows 11

Selenium version

4.12.4

What are the browser(s) and version(s) where you see this issue?

Edge WebView2 116

What are the browser driver(s) and version(s) where you see this issue?

Whichever one Selenium downloads (or doesn’t in this case)

Are you using Selenium Grid?

No

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 38 (27 by maintainers)

Commits related to this issue

Most upvoted comments

I believe I already reported that, at the end of this snippet:

But the test fails as follows:

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 404. Message: unknown command: must specify a binary when using WebView2 launch 
Host info: host: 'DESKTOP-2KE0PTJ', ip: '192.168.56.1'
Build info: version: '4.14.1', revision: '03f8ede370'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.15'
Driver info: org.openqa.selenium.edge.EdgeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: webview2, ms:edgeOptions: {args: [], binary: , extensions: []}}]}]