diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index fdf1b6127c34c..4e9097427f007 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -54,7 +54,18 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds protected WebDriver(ICommandExecutor executor, ICapabilities capabilities) { this.executor = executor; - this.StartSession(capabilities); + + try + { + this.StartSession(capabilities); + } + catch (Exception) + { + // Failed to start driver session, disposing of driver + this.Quit(); + throw; + } + this.elementFactory = new WebElementFactory(this); this.network = new NetworkManager(this); this.registeredCommands.AddRange(DriverCommand.KnownCommands); @@ -692,7 +703,6 @@ protected virtual void Dispose(bool disposing) { this.sessionId = null; } - this.executor.Dispose(); }