Skip to content

Commit 86156cb

Browse files
[dotnet] Fix null warnings in RelativeBy by sealing the type (#15379)
* [dotnet] Fix null warnings in `RelativeBy` by sealing the type * minimize changes * Address other low-hanging nullability warnings * Seal the type explicitly
1 parent 9ef1441 commit 86156cb

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

dotnet/src/support/Extensions/WebDriverExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static void ExecuteJavaScript(this IWebDriver driver, string script, para
115115
}
116116
}
117117

118-
private static object ExecuteJavaScriptInternal(IWebDriver driver, string script, object?[] args)
118+
private static object? ExecuteJavaScriptInternal(IWebDriver driver, string script, object?[] args)
119119
{
120120
IJavaScriptExecutor? executor = GetDriverAs<IJavaScriptExecutor>(driver)
121121
?? throw new WebDriverException("Driver does not implement IJavaScriptExecutor");

dotnet/src/support/UI/SelectElement.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public SelectElement(IWebElement element)
5353
this.WrappedElement = element;
5454

5555
// let check if it's a multiple
56-
string attribute = element.GetAttribute("multiple");
56+
string? attribute = element.GetAttribute("multiple");
5757
this.IsMultiple = attribute != null && !attribute.Equals("false", StringComparison.OrdinalIgnoreCase);
5858
}
5959

dotnet/src/webdriver/RelativeBy.cs

+5-9
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@ namespace OpenQA.Selenium
2929
/// <summary>
3030
/// Provides a mechanism for finding elements spatially relative to other elements.
3131
/// </summary>
32-
public class RelativeBy : By
32+
public sealed class RelativeBy : By
3333
{
3434
private readonly string wrappedAtom;
3535
private readonly object root;
3636
private readonly List<object> filters = new List<object>();
3737

38-
/// <summary>
39-
/// Prevents a default instance of the <see cref="RelativeBy"/> class.
40-
/// </summary>
41-
protected RelativeBy() : base()
38+
private static string GetWrappedAtom()
4239
{
4340
string atom;
4441
using (Stream atomStream = ResourceUtilities.GetResourceStream("find-elements.js", "find-elements.js"))
@@ -49,13 +46,13 @@ protected RelativeBy() : base()
4946
}
5047
}
5148

52-
wrappedAtom = string.Format(CultureInfo.InvariantCulture, "/* findElements */return ({0}).apply(null, arguments);", atom);
49+
return string.Format(CultureInfo.InvariantCulture, "/* findElements */return ({0}).apply(null, arguments);", atom);
5350
}
5451

55-
private RelativeBy(object root, List<object>? filters = null) : this()
52+
private RelativeBy(object root, List<object>? filters = null)
5653
{
54+
this.wrappedAtom = GetWrappedAtom();
5755
this.root = GetSerializableRoot(root);
58-
5956
if (filters != null)
6057
{
6158
this.filters.AddRange(filters);
@@ -73,7 +70,6 @@ public static RelativeBy WithLocator(By by)
7370
return new RelativeBy(by);
7471
}
7572

76-
7773
/// <summary>
7874
/// Finds the first element matching the criteria.
7975
/// </summary>

0 commit comments

Comments
 (0)