This commit is contained in:
Josh at WLTechBlog 2025-08-19 05:58:18 -05:00
parent 42cd4ff9b7
commit 58e361ba70
1 changed files with 11 additions and 13 deletions

View File

@ -3497,21 +3497,19 @@ 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 page.Eval to avoid element.Eval issues // Try to find and select by matching option value using page.Eval
script := fmt.Sprintf(`(function(){ var el = document.querySelector("%s"); if(el) { el.value = "%s"; el.dispatchEvent(new Event('change', { bubbles: true })); } })()`, interaction.Selector, interaction.Value) script := fmt.Sprintf(`(function(){ var el = document.querySelector("%s"); if(el) { el.value = "%s"; el.dispatchEvent(new Event('change', { bubbles: true })); } })()`, interaction.Selector, interaction.Value)
_, jsErr := page.Eval(script) // Execute JavaScript and ignore any rod evaluation quirks
if jsErr == nil { page.Eval(script)
// Verify the JavaScript selection worked by checking the element's value
currentValue, err := element.Property("value") // Always verify success by checking the element's actual value
if err != nil { currentValue, err := element.Property("value")
interactionResult.Error = fmt.Sprintf("failed to verify selection: %v", err) if err != nil {
} else if currentValue.Str() == interaction.Value { interactionResult.Error = fmt.Sprintf("failed to verify selection: %v", err)
interactionResult.Success = true } else if currentValue.Str() == interaction.Value {
} else { interactionResult.Success = true
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", jsErr) interactionResult.Error = fmt.Sprintf("failed to select option: %s (current value: %s)", interaction.Value, currentValue.Str())
} }
} else { } else {
interactionResult.Success = true interactionResult.Success = true