-
-
Notifications
You must be signed in to change notification settings - Fork 582
feat(playwright): handle <select> dropdowns in DropDown action #1113
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
Conversation
instead of the provided input state.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the Playwright WebDriver's dropdown handling by adding native <select>
element support to the DoAction
method. Previously, the implementation only handled div-based dropdowns, but now it can intelligently detect and handle both native HTML select elements and custom div-based dropdowns.
Key changes:
- Added automatic detection of element type (select vs div) using tag name evaluation
- Extracted select-specific logic into a dedicated
HandleSelectDropDownAsync
method - Implemented current value comparison to avoid unnecessary selections and network calls
var selectedText = await locator.Locator("option:checked").InnerTextAsync(); | ||
|
Copilot
AI
Jul 28, 2025
There was a problem hiding this comment.
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()
.
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.
await locator.SelectOptionAsync(new SelectOptionValue | ||
{ | ||
Label = action.Content | ||
}); | ||
|
Copilot
AI
Jul 28, 2025
There was a problem hiding this comment.
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.
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.
Label = action.Content | ||
}); | ||
|
||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle); |
Copilot
AI
Jul 28, 2025
There was a problem hiding this comment.
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.
HandleSelectDropDownAsync
NetworkIdle
after postback-triggered changeDoAction
when action type is DropDownPR Type
Enhancement
Description
Added native
<select>
dropdown support in Playwright WebDriverExtracted select handling logic into dedicated method
Added current value comparison to avoid unnecessary changes
Implemented network idle waiting after selection
Diagram Walkthrough
File Walkthrough
PlaywrightWebDriver.DoAction.cs
Enhanced dropdown handling with native select support
src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.DoAction.cs
from div dropdowns Extracted HandleSelectDropDownAsync method for native select handling Added current value comparison before selection Implemented network idle waiting after option selection