System.InvalidOperationException: session not created: Microsoft Edge failed to start: crashed

Code Toaster 0 Reputation points
2024-08-02T01:31:03.38+00:00

We have a Selenium automation that uses ChromeDriver to login to a web page, which works fine. I'm working on converting this to use EdgeDriver. When we use ChromeDriver we use the following options:

        private DriverOptions GetDriverOptions(Type driverType)
		{
			DriverOptions options = null;
			if (driverType == typeof(ChromeDriver))
			{
				options = new ChromeOptions();
                (options as ChromeOptions).AddArgument("no-sandbox");
                (options as ChromeOptions).AddArgument("--headless");
                (options as ChromeOptions).AddArgument("--window-size=1920,1080");
                (options as ChromeOptions).AddArgument("--start-maximized");
            }
			else if (driverType == typeof(EdgeDriver))
			{
				options = new EdgeOptions();
			}
          ...
            return options;
        }

After I switched to EdgeDriver I started to get an exception:

System.InvalidOperationException: session not created: Microsoft Edge failed to start: crashed.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so msedgedriver is assuming that msedge has crashed.) (SessionNotCreated)
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.<ExecuteAsync>d__63.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.StartSession(ICapabilities capabilities)
   at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
   at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout)

I tried other arguments (like --remote-debugging-port=), but still got more or less the same exception. I use Edge browser 127.0.2651.74 and the same version of Edge driver, Selenium.WebDriver 4.23.0 on Windows 2016 server. Any suggestion would be appreciated.

Microsoft Edge | Microsoft Edge development
{count} votes

1 answer

Sort by: Most helpful
  1. Jinxin Wang (Shanghai Wicresoft Co Ltd) 2,195 Reputation points Microsoft External Staff
    2024-08-02T08:21:19.6133333+00:00

    Hi @Code Toaster,You could try the following possible solutions:

    1.Make sure you are using the latest version of Microsoft Edge (127.0.2651.86) and Edge driver.

    2.Kill all the processes of Microsoft Edge in Task Manager before you run the code and test again.

    3.You can try to keep only Edge options and remove Chrome options. As show below:

     var options = new EdgeOptions();
     options.AddArgument("--start-maximized");
     options.AddArgument("no-sandbox");
     options.AddArgument("--headless");
    
    
    

    If the above method still does not work, you can try the following method.

    1.Back up your User Data folder in the same path. Here for example, I back up the User Data folder as User Data1:

    User's image

    2.Use User Data1 in your code to specify using Default profile when run Edge with Selenium:

    var options = new EdgeOptions();
    var service = EdgeDriverService.CreateDefaultService("C:\\Users\\XYZ\\ABC\\", "msedgedriver.exe");
    options.AddArgument("user-data-dir=C:\\Users\\XYZ\\AppData\\Local\\Microsoft\\Edge\\User Data1");
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    Jinxin Wang

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.