Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,23 @@ await locator.ClickAsync(new LocatorClickOptions
}
else if (action.Action == BroswerActionEnum.DropDown)
{
await locator.ClickAsync();
var optionLocator = page.Locator($"//div[text()='{action.Content}']");
var optionCount = await optionLocator.CountAsync(); ;
if (optionCount == 0)
var tagName = await locator.EvaluateAsync<string>("el => el.tagName.toLowerCase()");
if (tagName == "select")
{
Serilog.Log.Error($"Dropdown option not found: {action.Content}");
return;
await HandleSelectDropDownAsync(page, locator, action);
}
else
{
await locator.ClickAsync();
var optionLocator = page.Locator($"//div[text()='{action.Content}']");
var optionCount = await optionLocator.CountAsync();
if (optionCount == 0)
{
Serilog.Log.Error($"Dropdown option not found: {action.Content}");
return;
}
await optionLocator.First.ClickAsync();
}
await optionLocator.First.ClickAsync();
}
else if (action.Action == BroswerActionEnum.InputText)
{
Expand Down Expand Up @@ -247,4 +255,29 @@ public static List<int> GetVelocityTrack(float distance)

return track;
}

private async Task HandleSelectDropDownAsync(IPage page, ILocator locator, ElementActionArgs action)
{
if (string.IsNullOrWhiteSpace(action.Content))
{
throw new InvalidOperationException("Dropdown target option (action.Content) cannot be null or empty when using a <select> element.");
}

var selectedText = await locator.Locator("option:checked").InnerTextAsync();

Comment on lines +266 to +267
Copy link

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will throw an exception if no option is currently selected in the select element. Consider using FirstOrDefaultAsync() or checking if any options are selected before calling InnerTextAsync().

Suggested change
var selectedText = await locator.Locator("option:checked").InnerTextAsync();
var selectedOptionLocator = locator.Locator("option:checked");
var selectedOptionCount = await selectedOptionLocator.CountAsync();
string selectedText = null;
if (selectedOptionCount > 0)
{
selectedText = await selectedOptionLocator.InnerTextAsync();
}
else
{
_logger.LogWarning("No option is currently selected in the dropdown.");
}

Copilot uses AI. Check for mistakes.

if (!string.Equals(selectedText?.Trim(), action.Content.Trim(), StringComparison.OrdinalIgnoreCase))
{
await locator.SelectOptionAsync(new SelectOptionValue
{
Label = action.Content
});

Comment on lines +270 to +274
Copy link

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selecting by label may fail if the option text doesn't exactly match. Consider also trying to select by value if label selection fails, or use a more robust selection strategy that handles both scenarios.

Suggested change
await locator.SelectOptionAsync(new SelectOptionValue
{
Label = action.Content
});
var selectionResult = await locator.SelectOptionAsync(new SelectOptionValue
{
Label = action.Content
});
if (selectionResult == null || selectionResult.Length == 0)
{
_logger.LogWarning($"Failed to select dropdown option by label: {action.Content}. Attempting to select by value.");
selectionResult = await locator.SelectOptionAsync(new SelectOptionValue
{
Value = action.Content
});
if (selectionResult == null || selectionResult.Length == 0)
{
throw new InvalidOperationException($"Failed to select dropdown option by both label and value: {action.Content}");
}
}

Copilot uses AI. Check for mistakes.

await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
Copy link

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for NetworkIdle after every select option change may cause unnecessary delays, especially if the select doesn't trigger network requests. Consider making this configurable or adding a timeout to prevent indefinite waiting.

Copilot uses AI. Check for mistakes.

_logger.LogInformation($"Dropdown changed to: {action.Content}");
}
else
{
_logger.LogInformation($"Dropdown already on correct option: {action.Content}");
}
}
}
Loading