diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index 33266516d2184..6125490529a39 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -62,8 +62,15 @@ protected WebDriver(ICommandExecutor executor, ICapabilities capabilities) } catch (Exception) { - // Failed to start driver session, disposing of driver - this.Quit(); + try + { + // Failed to start driver session, disposing of driver + this.Quit(); + } + catch + { + // Ignore the clean-up exception. We'll propagate the original failure. + } throw; } @@ -703,7 +710,10 @@ protected virtual void Dispose(bool disposing) { try { - this.Execute(DriverCommand.Quit, null); + if (this.sessionId is not null) + { + this.Execute(DriverCommand.Quit, null); + } } catch (NotImplementedException) {