Skip to content

[dotnet] [bidi] Make Locator types as not nested #15429

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

Merged
merged 3 commits into from
Mar 17, 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
53 changes: 29 additions & 24 deletions dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,42 @@
namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;

[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
[JsonDerivedType(typeof(Accessibility), "accessibility")]
[JsonDerivedType(typeof(Css), "css")]
[JsonDerivedType(typeof(InnerText), "innerText")]
[JsonDerivedType(typeof(XPath), "xpath")]
public abstract record Locator
[JsonDerivedType(typeof(AccessibilityLocator), "accessibility")]
[JsonDerivedType(typeof(CssLocator), "css")]
[JsonDerivedType(typeof(ContextLocator), "context")]
[JsonDerivedType(typeof(InnerTextLocator), "innerText")]
[JsonDerivedType(typeof(XPathLocator), "xpath")]
public abstract record Locator;

public record AccessibilityLocator(AccessibilityLocator.AccessibilityLocatorValue Value) : Locator
{
public record Accessibility(Accessibility.AccessibilityValue Value) : Locator
public record AccessibilityLocatorValue
{
public record AccessibilityValue
{
public string? Name { get; set; }
public string? Role { get; set; }
}
public string? Name { get; set; }
public string? Role { get; set; }
}
}

public record Css(string Value) : Locator;
public record CssLocator(string Value) : Locator;

public record InnerText(string Value) : Locator
{
public bool? IgnoreCase { get; set; }
public record ContextLocator(ContextLocator.ContextLocatorValue Value) : Locator
{
public record ContextLocatorValue(BrowsingContext Context);
}

public MatchType? MatchType { get; set; }
public record InnerTextLocator(string Value) : Locator
{
public bool? IgnoreCase { get; set; }

public long? MaxDepth { get; set; }
}
public Match? MatchType { get; set; }

public record XPath(string Value) : Locator;
}
public long? MaxDepth { get; set; }

public enum MatchType
{
Full,
Partial
public enum Match
{
Full,
Partial
}
}

public record XPathLocator(string Value) : Locator;
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public async Task CanCaptureScreenshotOfElement()
{
await context.NavigateAsync(UrlBuilder.WhereIs("formPage.html"), new() { Wait = ReadinessState.Complete });

var nodes = await context.LocateNodesAsync(new Locator.Css("#checky"));
var nodes = await context.LocateNodesAsync(new CssLocator("#checky"));

var screenshot = await context.CaptureScreenshotAsync(new()
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task TestShiftClickingOnMultiSelectionList()
{
driver.Url = UrlBuilder.WhereIs("formSelectionPage.html");

var options = await context.LocateNodesAsync(new Locator.Css("option"));
var options = await context.LocateNodesAsync(new CssLocator("option"));

await context.Input.PerformActionsAsync([
new PointerActions
Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/common/BiDi/Input/SetFilesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task CanSetFiles()
{
driver.Url = UrlBuilder.WhereIs("formPage.html");

var nodes = await context.LocateNodesAsync(new Locator.Css("[id='upload']"));
var nodes = await context.LocateNodesAsync(new CssLocator("[id='upload']"));

await context.Input.SetFilesAsync(nodes[0], [_tempFile]);

Expand Down
Loading