This commit is contained in:
Josh at WLTechBlog 2025-08-18 15:10:59 -05:00
parent dd55c67ad4
commit 439ae4b5f7
1 changed files with 10 additions and 7 deletions

View File

@ -3497,13 +3497,16 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) (
err = element.Select([]string{interaction.Value}, true, rod.SelectorTypeText) err = element.Select([]string{interaction.Value}, true, rod.SelectorTypeText)
if err != nil { if err != nil {
// If text selection failed, the value might be the actual option value // If text selection failed, the value might be the actual option value
// Try to find and select by matching option value using JavaScript // Try to find and select by matching option value using page.Eval to avoid element.Eval issues
script := fmt.Sprintf("this.value = '%s'", interaction.Value) script := fmt.Sprintf(`
_, jsErr := element.Eval(script) const element = document.querySelector("%s");
if (element) {
element.value = "%s";
element.dispatchEvent(new Event('change', { bubbles: true }));
}
`, interaction.Selector, interaction.Value)
_, jsErr := page.Eval(script)
if jsErr == nil { if jsErr == nil {
// Trigger change event
_, _ = element.Eval("this.dispatchEvent(new Event('change', { bubbles: true }))")
// Verify the JavaScript selection worked by checking the element's value // Verify the JavaScript selection worked by checking the element's value
currentValue, err := element.Property("value") currentValue, err := element.Property("value")
if err != nil { if err != nil {
@ -3514,7 +3517,7 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) (
interactionResult.Error = fmt.Sprintf("failed to select option: %s (current value: %s)", interaction.Value, currentValue.Str()) interactionResult.Error = fmt.Sprintf("failed to select option: %s (current value: %s)", interaction.Value, currentValue.Str())
} }
} else { } else {
interactionResult.Error = fmt.Sprintf("failed to select option: %v", err) interactionResult.Error = fmt.Sprintf("failed to select option: %v", jsErr)
} }
} else { } else {
interactionResult.Success = true interactionResult.Success = true