Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Fix null warnings in RelativeBy by sealing the type #15379

Merged
merged 5 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotnet/src/support/Extensions/WebDriverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static void ExecuteJavaScript(this IWebDriver driver, string script, para
}
}

private static object ExecuteJavaScriptInternal(IWebDriver driver, string script, object?[] args)
private static object? ExecuteJavaScriptInternal(IWebDriver driver, string script, object?[] args)
{
IJavaScriptExecutor? executor = GetDriverAs<IJavaScriptExecutor>(driver)
?? throw new WebDriverException("Driver does not implement IJavaScriptExecutor");
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/support/UI/SelectElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public SelectElement(IWebElement element)
this.WrappedElement = element;

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

Expand Down
14 changes: 5 additions & 9 deletions dotnet/src/webdriver/RelativeBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ namespace OpenQA.Selenium
/// <summary>
/// Provides a mechanism for finding elements spatially relative to other elements.
/// </summary>
public class RelativeBy : By
public sealed class RelativeBy : By
{
private readonly string wrappedAtom;
private readonly object root;
private readonly List<object> filters = new List<object>();

/// <summary>
/// Prevents a default instance of the <see cref="RelativeBy"/> class.
/// </summary>
protected RelativeBy() : base()
private static string GetWrappedAtom()
{
string atom;
using (Stream atomStream = ResourceUtilities.GetResourceStream("find-elements.js", "find-elements.js"))
Expand All @@ -49,13 +46,13 @@ protected RelativeBy() : base()
}
}

wrappedAtom = string.Format(CultureInfo.InvariantCulture, "/* findElements */return ({0}).apply(null, arguments);", atom);
return string.Format(CultureInfo.InvariantCulture, "/* findElements */return ({0}).apply(null, arguments);", atom);
}

private RelativeBy(object root, List<object>? filters = null) : this()
private RelativeBy(object root, List<object>? filters = null)
{
this.wrappedAtom = GetWrappedAtom();
this.root = GetSerializableRoot(root);

if (filters != null)
{
this.filters.AddRange(filters);
Expand All @@ -73,7 +70,6 @@ public static RelativeBy WithLocator(By by)
return new RelativeBy(by);
}


/// <summary>
/// Finds the first element matching the criteria.
/// </summary>
Expand Down
Loading