From 940c5549429d01959c46d7c75c68a8c04abbfb72 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 1 Mar 2025 02:15:37 -0500 Subject: [PATCH 1/2] [dotnet] Annotate nullability on elements and `WebDriver` --- .../support/Events/EventFiringWebDriver.cs | 40 ++++------- dotnet/src/webdriver/By.cs | 3 +- dotnet/src/webdriver/Command.cs | 10 +-- dotnet/src/webdriver/CookieJar.cs | 2 +- dotnet/src/webdriver/IJavascriptExecutor.cs | 8 ++- dotnet/src/webdriver/IWebDriver.cs | 2 + dotnet/src/webdriver/IWebElement.cs | 8 ++- dotnet/src/webdriver/RelativeBy.cs | 2 +- dotnet/src/webdriver/ShadowRoot.cs | 2 +- dotnet/src/webdriver/TargetLocator.cs | 4 +- dotnet/src/webdriver/WebDriver.cs | 66 +++++++++---------- dotnet/src/webdriver/WebElement.cs | 26 +++----- dotnet/src/webdriver/WebElementFactory.cs | 3 + 13 files changed, 82 insertions(+), 94 deletions(-) diff --git a/dotnet/src/support/Events/EventFiringWebDriver.cs b/dotnet/src/support/Events/EventFiringWebDriver.cs index ba9a8e811fd5d..9f0355cc204cd 100644 --- a/dotnet/src/support/Events/EventFiringWebDriver.cs +++ b/dotnet/src/support/Events/EventFiringWebDriver.cs @@ -442,14 +442,14 @@ public void Dispose() /// variable, as if the function were called via "Function.apply" /// /// - public object ExecuteScript(string script, params object?[] args) + public object? ExecuteScript(string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { throw new NotSupportedException("Underlying driver instance does not support executing JavaScript"); } - object scriptResult; + object? scriptResult; try { object?[] unwrappedArgs = UnwrapElementArguments(args); @@ -505,7 +505,7 @@ public object ExecuteScript(string script, params object?[] args) /// variable, as if the function were called via "Function.apply" /// /// - public object ExecuteScript(PinnedScript script, params object?[] args) + public object? ExecuteScript(PinnedScript script, params object?[] args) { if (script == null) { @@ -517,7 +517,7 @@ public object ExecuteScript(PinnedScript script, params object?[] args) throw new NotSupportedException("Underlying driver instance does not support executing JavaScript"); } - object scriptResult; + object? scriptResult; try { object?[] unwrappedArgs = UnwrapElementArguments(args); @@ -542,14 +542,14 @@ public object ExecuteScript(PinnedScript script, params object?[] args) /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - public object ExecuteAsyncScript(string script, params object?[] args) + public object? ExecuteAsyncScript(string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { throw new NotSupportedException("Underlying driver instance does not support executing JavaScript"); } - object scriptResult; + object? scriptResult; try { object?[] unwrappedArgs = UnwrapElementArguments(args); @@ -1589,20 +1589,17 @@ public void Click() /// /// Attribute you wish to get details of /// The attribute's current value or null if the value is not set. - public string GetAttribute(string attributeName) + public string? GetAttribute(string attributeName) { - string attribute; try { - attribute = this.WrappedElement.GetAttribute(attributeName); + return this.WrappedElement.GetAttribute(attributeName); } catch (Exception ex) { this.parentDriver.OnException(new WebDriverExceptionEventArgs(this.parentDriver, ex)); throw; } - - return attribute; } /// @@ -1617,20 +1614,17 @@ public string GetAttribute(string attributeName) /// of an IDL property of the element, either use the /// method or the method. /// - public string GetDomAttribute(string attributeName) + public string? GetDomAttribute(string attributeName) { - string attribute; try { - attribute = this.WrappedElement.GetDomAttribute(attributeName); + return this.WrappedElement.GetDomAttribute(attributeName); } catch (Exception ex) { this.parentDriver.OnException(new WebDriverExceptionEventArgs(this.parentDriver, ex)); throw; } - - return attribute; } /// @@ -1639,20 +1633,17 @@ public string GetDomAttribute(string attributeName) /// The name of the JavaScript property to get the value of. /// The JavaScript property's current value. Returns a if the /// value is not set or the property does not exist. - public string GetDomProperty(string propertyName) + public string? GetDomProperty(string propertyName) { - string elementProperty; try { - elementProperty = this.WrappedElement.GetDomProperty(propertyName); + return this.WrappedElement.GetDomProperty(propertyName); } catch (Exception ex) { this.parentDriver.OnException(new WebDriverExceptionEventArgs(this.parentDriver, ex)); throw; } - - return elementProperty; } /// @@ -1683,22 +1674,19 @@ public string GetCssValue(string propertyName) /// A shadow root representation. public ISearchContext GetShadowRoot() { - ISearchContext shadowRoot; try { GetShadowRootEventArgs e = new GetShadowRootEventArgs(this.parentDriver.WrappedDriver, this.WrappedElement); this.parentDriver.OnGettingShadowRoot(e); - shadowRoot = this.WrappedElement.GetShadowRoot(); + ISearchContext shadowRoot = this.WrappedElement.GetShadowRoot(); this.parentDriver.OnGetShadowRootCompleted(e); - shadowRoot = new EventFiringShadowRoot(this.parentDriver, shadowRoot); + return new EventFiringShadowRoot(this.parentDriver, shadowRoot); } catch (Exception ex) { this.parentDriver.OnException(new WebDriverExceptionEventArgs(this.parentDriver, ex)); throw; } - - return shadowRoot; } /// diff --git a/dotnet/src/webdriver/By.cs b/dotnet/src/webdriver/By.cs index e0f498931ed64..2081e3d8e4a6e 100644 --- a/dotnet/src/webdriver/By.cs +++ b/dotnet/src/webdriver/By.cs @@ -99,7 +99,7 @@ protected By(Func findElementMethod, Func - /// Gets or sets the method used to find a single element matching specified criteria. + /// Gets or sets the method used to find a single element matching specified criteria, or throws if no element is found. /// protected Func? FindElementMethod { get; set; } @@ -324,6 +324,7 @@ public static By CssSelector(string cssSelectorToFind) /// /// An object to use to search for the elements. /// The first matching on the current context. + /// If no element matches the criteria. public virtual IWebElement FindElement(ISearchContext context) { if (this.FindElementMethod is not { } findElementMethod) diff --git a/dotnet/src/webdriver/Command.cs b/dotnet/src/webdriver/Command.cs index 3a44422a00f84..4714c638c5ed8 100644 --- a/dotnet/src/webdriver/Command.cs +++ b/dotnet/src/webdriver/Command.cs @@ -56,10 +56,10 @@ public Command(string name, string jsonParameters) /// Name of the command /// Parameters for that command /// If is . - public Command(SessionId? sessionId, string name, Dictionary? parameters) + public Command(SessionId? sessionId, string name, Dictionary? parameters) { this.SessionId = sessionId; - this.Parameters = parameters ?? new Dictionary(); + this.Parameters = parameters ?? new Dictionary(); this.Name = name ?? throw new ArgumentNullException(nameof(name)); } @@ -79,7 +79,7 @@ public Command(SessionId? sessionId, string name, Dictionary? pa /// Gets the parameters of the command /// [JsonPropertyName("parameters")] - public Dictionary Parameters { get; } + public Dictionary Parameters { get; } /// /// Gets the parameters of the command as a JSON-encoded string. @@ -118,9 +118,9 @@ public override string ToString() /// A with a string keys, and an object value. /// If is not a JSON object. /// If is . - private static Dictionary? ConvertParametersFromJson(string value) + private static Dictionary? ConvertParametersFromJson(string value) { - Dictionary? parameters = JsonSerializer.Deserialize>(value, s_jsonSerializerOptions); + Dictionary? parameters = JsonSerializer.Deserialize>(value, s_jsonSerializerOptions); return parameters; } } diff --git a/dotnet/src/webdriver/CookieJar.cs b/dotnet/src/webdriver/CookieJar.cs index 32674b24c4e43..4d25f8b5c4714 100644 --- a/dotnet/src/webdriver/CookieJar.cs +++ b/dotnet/src/webdriver/CookieJar.cs @@ -127,7 +127,7 @@ public void DeleteAllCookies() { var rawCookie = driver.InternalExecute(DriverCommand.GetCookie, new() { { "name", name } }).Value; - return Cookie.FromDictionary((Dictionary)rawCookie!); + return Cookie.FromDictionary((Dictionary)rawCookie!); } catch (NoSuchCookieException) { diff --git a/dotnet/src/webdriver/IJavascriptExecutor.cs b/dotnet/src/webdriver/IJavascriptExecutor.cs index fcbf9080efd2c..addfecae7eef6 100644 --- a/dotnet/src/webdriver/IJavascriptExecutor.cs +++ b/dotnet/src/webdriver/IJavascriptExecutor.cs @@ -20,6 +20,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium { /// @@ -62,7 +64,7 @@ public interface IJavaScriptExecutor /// variable, as if the function were called via "Function.apply" /// /// - object ExecuteScript(string script, params object[] args); + object? ExecuteScript(string script, params object?[] args); /// /// Executes JavaScript in the context of the currently selected frame or window. @@ -100,7 +102,7 @@ public interface IJavaScriptExecutor /// /// /// If is . - object ExecuteScript(PinnedScript script, params object[] args); + object? ExecuteScript(PinnedScript script, params object?[] args); /// /// Executes JavaScript asynchronously in the context of the currently selected frame or window. @@ -108,6 +110,6 @@ public interface IJavaScriptExecutor /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - object ExecuteAsyncScript(string script, params object[] args); + object? ExecuteAsyncScript(string script, params object?[] args); } } diff --git a/dotnet/src/webdriver/IWebDriver.cs b/dotnet/src/webdriver/IWebDriver.cs index 9fba695808c4f..00120e4a5a105 100644 --- a/dotnet/src/webdriver/IWebDriver.cs +++ b/dotnet/src/webdriver/IWebDriver.cs @@ -20,6 +20,8 @@ using System; using System.Collections.ObjectModel; +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/IWebElement.cs b/dotnet/src/webdriver/IWebElement.cs index 7e0c7627cab2b..fc8737bae5403 100644 --- a/dotnet/src/webdriver/IWebElement.cs +++ b/dotnet/src/webdriver/IWebElement.cs @@ -20,6 +20,8 @@ using System; using System.Drawing; +#nullable enable + namespace OpenQA.Selenium { /// @@ -170,7 +172,7 @@ public interface IWebElement : ISearchContext /// /// /// Thrown when the target element is no longer valid in the document DOM. - string GetAttribute(string attributeName); + string? GetAttribute(string attributeName); /// /// Gets the value of a declared HTML attribute of this element. @@ -185,7 +187,7 @@ public interface IWebElement : ISearchContext /// of an IDL property of the element, either use the /// method or the method. /// - string GetDomAttribute(string attributeName); + string? GetDomAttribute(string attributeName); /// /// Gets the value of a JavaScript property of this element. @@ -194,7 +196,7 @@ public interface IWebElement : ISearchContext /// The JavaScript property's current value. Returns a if the /// value is not set or the property does not exist. /// Thrown when the target element is no longer valid in the document DOM. - string GetDomProperty(string propertyName); + string? GetDomProperty(string propertyName); /// /// Gets the value of a CSS property of this element. diff --git a/dotnet/src/webdriver/RelativeBy.cs b/dotnet/src/webdriver/RelativeBy.cs index cdd6bbe1c4a9d..f680fc3d0bcbb 100644 --- a/dotnet/src/webdriver/RelativeBy.cs +++ b/dotnet/src/webdriver/RelativeBy.cs @@ -108,7 +108,7 @@ public override ReadOnlyCollection FindElements(ISearchContext cont filterParameters["root"] = GetSerializableObject(this.root); filterParameters["filters"] = this.filters; parameters["relative"] = filterParameters; - object rawElements = js.ExecuteScript(wrappedAtom, parameters); + object? rawElements = js.ExecuteScript(wrappedAtom, parameters); if (rawElements is ReadOnlyCollection elements) { diff --git a/dotnet/src/webdriver/ShadowRoot.cs b/dotnet/src/webdriver/ShadowRoot.cs index a872d4fbc7d74..a616a7e14ebbc 100644 --- a/dotnet/src/webdriver/ShadowRoot.cs +++ b/dotnet/src/webdriver/ShadowRoot.cs @@ -99,7 +99,7 @@ public IWebElement FindElement(By by) parameters.Add("value", by.Criteria); Response commandResponse = this.driver.InternalExecute(DriverCommand.FindShadowChildElement, parameters); - return this.driver.GetElementFromResponse(commandResponse); + return this.driver.GetElementFromResponse(commandResponse)!; } /// diff --git a/dotnet/src/webdriver/TargetLocator.cs b/dotnet/src/webdriver/TargetLocator.cs index d8d57d933dcda..06dac9a3321d0 100644 --- a/dotnet/src/webdriver/TargetLocator.cs +++ b/dotnet/src/webdriver/TargetLocator.cs @@ -166,7 +166,7 @@ public IWebDriver Window(string windowHandleOrName) foreach (string handle in this.driver.WindowHandles) { this.Window(handle); - if (windowHandleOrName == this.driver.ExecuteScript("return window.name").ToString()) + if (windowHandleOrName == this.driver.ExecuteScript("return window.name")!.ToString()) { return this.driver; // found by name } @@ -223,7 +223,7 @@ public IWebDriver DefaultContent() public IWebElement ActiveElement() { Response response = this.driver.InternalExecute(DriverCommand.GetActiveElement, null); - return this.driver.GetElementFromResponse(response); + return this.driver.GetElementFromResponse(response)!; } /// diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index c83543e6f02fb..60ed1d3035f7d 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -28,6 +28,8 @@ using System.Globalization; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium { /// @@ -40,10 +42,10 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds /// protected static readonly TimeSpan DefaultCommandTimeout = TimeSpan.FromSeconds(60); private IFileDetector fileDetector = new DefaultFileDetector(); - private NetworkManager network; + private readonly NetworkManager network; private WebElementFactory elementFactory; - private List registeredCommands = new List(); + private readonly List registeredCommands = new List(); /// /// Initializes a new instance of the class. @@ -108,7 +110,7 @@ public string Url Response commandResponse = this.Execute(DriverCommand.GetCurrentUrl, null); commandResponse.EnsureValueIsNotNull(); - return commandResponse.Value.ToString(); + return commandResponse.Value.ToString()!; } set => new Navigator(this).GoToUrl(value); @@ -122,13 +124,11 @@ public string Title get { Response commandResponse = this.Execute(DriverCommand.GetTitle, null); - object returnedTitle = commandResponse.Value ?? string.Empty; - return returnedTitle.ToString(); + return commandResponse.Value?.ToString() ?? string.Empty; } } - /// /// Gets the source of the page last loaded by the browser. /// @@ -139,7 +139,7 @@ public string PageSource Response commandResponse = this.Execute(DriverCommand.GetPageSource, null); commandResponse.EnsureValueIsNotNull(); - return commandResponse.Value.ToString(); + return commandResponse.Value.ToString()!; } } @@ -154,7 +154,7 @@ public string CurrentWindowHandle Response commandResponse = this.Execute(DriverCommand.GetCurrentWindowHandle, null); commandResponse.EnsureValueIsNotNull(); - return commandResponse.Value.ToString(); + return commandResponse.Value.ToString()!; } } @@ -168,11 +168,11 @@ public ReadOnlyCollection WindowHandles Response commandResponse = this.Execute(DriverCommand.GetWindowHandles, null); commandResponse.EnsureValueIsNotNull(); - object[] handles = (object[])commandResponse.Value; + object?[] handles = (object?[])commandResponse.Value; List handleList = new List(handles.Length); - foreach (object handle in handles) + foreach (object? handle in handles) { - handleList.Add(handle.ToString()); + handleList.Add(handle!.ToString()!); } return handleList.AsReadOnly(); @@ -184,8 +184,6 @@ public ReadOnlyCollection WindowHandles /// public bool IsActionExecutor => true; -#nullable enable - /// /// Gets the for the current session of this driver. /// @@ -272,8 +270,6 @@ public void Dispose() return this.ExecuteScript(script.MakeExecutionScript(), args); } -#nullable restore - /// /// Finds the first element in the page that matches the object /// @@ -310,7 +306,7 @@ public virtual IWebElement FindElement(string mechanism, string value) Response commandResponse = this.Execute(DriverCommand.FindElement, parameters); - return this.GetElementFromResponse(commandResponse); + return this.GetElementFromResponse(commandResponse)!; } /// @@ -351,8 +347,6 @@ public virtual ReadOnlyCollection FindElements(string mechanism, st return this.GetElementsFromResponse(commandResponse); } -#nullable enable - /// /// Gets a object representing the image of the page on the screen. /// @@ -527,14 +521,8 @@ internal bool RegisterDriverCommand(string commandName, [NotNullWhen(true)] Comm /// /// Response from the browser /// Element from the page, or if the response does not contain a dictionary. - /// If is . internal IWebElement? GetElementFromResponse(Response response) { - if (response == null) - { - throw new NoSuchElementException(); - } - if (response.Value is Dictionary elementDictionary) { return this.elementFactory.CreateElement(elementDictionary); @@ -566,8 +554,6 @@ internal ReadOnlyCollection GetElementsFromResponse(Response respon return toReturn.AsReadOnly(); } -#nullable restore - /// /// Executes commands with the driver /// @@ -575,7 +561,11 @@ internal ReadOnlyCollection GetElementsFromResponse(Response respon /// Parameters needed for the command /// WebDriver Response /// If is . - internal Response InternalExecute(string driverCommandToExecute, Dictionary parameters) + internal Response InternalExecute(string driverCommandToExecute, Dictionary? parameters) { return Task.Run(() => this.InternalExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult(); } @@ -587,8 +577,11 @@ internal Response InternalExecute(string driverCommandToExecute, DictionaryParameters needed for the command /// A task object representing the asynchronous operation /// If is . - internal Task InternalExecuteAsync(string driverCommandToExecute, - Dictionary parameters) + internal Task InternalExecuteAsync(string driverCommandToExecute, Dictionary? parameters) { return this.ExecuteAsync(driverCommandToExecute, parameters); } @@ -600,8 +593,11 @@ internal Task InternalExecuteAsync(string driverCommandToExecute, /// A containing the names and values of the parameters of the command. /// A containing information about the success or failure of the command and any data returned by the command. /// If is . - protected virtual Response Execute(string driverCommandToExecute, - Dictionary parameters) + protected virtual Response Execute(string driverCommandToExecute, Dictionary? parameters) { return Task.Run(() => this.ExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult(); } @@ -613,7 +609,11 @@ protected virtual Response Execute(string driverCommandToExecute, /// A containing the names and values of the parameters of the command. /// A containing information about the success or failure of the command and any data returned by the command. /// If is . - protected virtual async Task ExecuteAsync(string driverCommandToExecute, Dictionary parameters) + protected virtual async Task ExecuteAsync(string driverCommandToExecute, Dictionary? parameters) { Command commandToExecute = new Command(SessionId, driverCommandToExecute, parameters); @@ -702,8 +702,6 @@ protected virtual Dictionary GetCapabilitiesDictionary(ICapabili return capabilitiesDictionary; } -#nullable enable - /// /// Registers a command to be executed with this driver instance as an internally known driver command. /// diff --git a/dotnet/src/webdriver/WebElement.cs b/dotnet/src/webdriver/WebElement.cs index 8b7c17c8b4b3e..3a626729320cd 100644 --- a/dotnet/src/webdriver/WebElement.cs +++ b/dotnet/src/webdriver/WebElement.cs @@ -28,6 +28,8 @@ using System.IO.Compression; using System.Linq; +#nullable enable + namespace OpenQA.Selenium { /// @@ -40,8 +42,6 @@ public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable, /// public const string ElementReferencePropertyName = "element-6066-11e4-a52e-4f735466cecf"; -#nullable enable - private readonly WebDriver driver; /// @@ -327,8 +327,6 @@ public virtual void Click() this.Execute(DriverCommand.ClickElement, parameters); } -#nullable restore - /// /// Finds the first using the given method. /// @@ -346,8 +344,6 @@ public virtual IWebElement FindElement(By by) return by.FindElement(this); } -#nullable enable - /// /// Finds a child element matching the given mechanism and value. /// @@ -363,11 +359,9 @@ public virtual IWebElement FindElement(string mechanism, string value) Response commandResponse = this.Execute(DriverCommand.FindChildElement, parameters); - return this.driver.GetElementFromResponse(commandResponse); + return this.driver.GetElementFromResponse(commandResponse)!; } -#nullable restore - /// /// Finds all IWebElements within the current context /// using the given mechanism. @@ -385,8 +379,6 @@ public virtual ReadOnlyCollection FindElements(By by) return by.FindElements(this); } -#nullable enable - /// /// Finds all child elements matching the given mechanism and value. /// @@ -701,24 +693,24 @@ Dictionary IWebDriverObjectReference.ToDictionary() return elementDictionary; } -#nullable restore - /// /// Executes a command on this element using the specified parameters. /// /// The to execute against this element. /// A containing names and values of the parameters for the command. /// The object containing the result of the command execution. - protected virtual Response Execute(string commandToExecute, Dictionary parameters) + protected virtual Response Execute(string commandToExecute, Dictionary? parameters) { return this.driver.InternalExecute(commandToExecute, parameters); } -#nullable enable - private static string GetAtom(string atomResourceName) { - string atom = string.Empty; + string atom; using (Stream atomStream = ResourceUtilities.GetResourceStream(atomResourceName, atomResourceName)) { using (StreamReader atomReader = new StreamReader(atomStream)) diff --git a/dotnet/src/webdriver/WebElementFactory.cs b/dotnet/src/webdriver/WebElementFactory.cs index 80ff907ebdc2f..db79bb888b56a 100644 --- a/dotnet/src/webdriver/WebElementFactory.cs +++ b/dotnet/src/webdriver/WebElementFactory.cs @@ -49,6 +49,9 @@ public WebElementFactory(WebDriver parentDriver) /// /// The dictionary containing the element reference. /// A containing the information from the specified dictionary. + /// If is . + /// If the dictionary does not contain the element reference property name. + /// If the element property is or . public virtual WebElement CreateElement(Dictionary elementDictionary) { string elementId = this.GetElementId(elementDictionary); From 3fee4c12d21a319a54539906463b28221dfe9413 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 1 Mar 2025 02:20:27 -0500 Subject: [PATCH 2/2] Fix null warnings --- dotnet/src/webdriver/Chromium/ChromiumDriver.cs | 2 +- dotnet/src/webdriver/Firefox/FirefoxDriver.cs | 2 +- dotnet/src/webdriver/Firefox/FirefoxProfile.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs index f1fc0503f8b0f..08b69b4859f30 100644 --- a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs +++ b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs @@ -168,7 +168,7 @@ private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverServi string fullServicePath = finder.GetDriverPath(); service.DriverServicePath = Path.GetDirectoryName(fullServicePath); service.DriverServiceExecutableName = Path.GetFileName(fullServicePath); - if (finder.TryGetBrowserPath(out string browserPath)) + if (finder.TryGetBrowserPath(out string? browserPath)) { options.BinaryLocation = browserPath; options.BrowserVersion = null; diff --git a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs index 98a1e43ce056a..57d82799f000f 100644 --- a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs +++ b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs @@ -221,7 +221,7 @@ private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverServi string fullServicePath = finder.GetDriverPath(); service.DriverServicePath = Path.GetDirectoryName(fullServicePath); service.DriverServiceExecutableName = Path.GetFileName(fullServicePath); - if (finder.TryGetBrowserPath(out string browserPath)) + if (finder.TryGetBrowserPath(out string? browserPath)) { options.BinaryLocation = browserPath; options.BrowserVersion = null; diff --git a/dotnet/src/webdriver/Firefox/FirefoxProfile.cs b/dotnet/src/webdriver/Firefox/FirefoxProfile.cs index 1814e35b0ca7a..dbf4eb5d83790 100644 --- a/dotnet/src/webdriver/Firefox/FirefoxProfile.cs +++ b/dotnet/src/webdriver/Firefox/FirefoxProfile.cs @@ -160,7 +160,7 @@ public void WriteToDisk() this.ProfileDirectory = GenerateProfileDirectoryName(); if (!string.IsNullOrEmpty(this.sourceProfileDir)) { - FileUtilities.CopyDirectory(this.sourceProfileDir, this.ProfileDirectory); + FileUtilities.CopyDirectory(this.sourceProfileDir!, this.ProfileDirectory); } else {