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)
if err != nil {
// 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)
_, jsErr := page.Eval(script)
if jsErr == nil {
// Verify the JavaScript selection worked by checking the element's value
currentValue, err := element.Property("value")
if err != nil {
interactionResult.Error = fmt.Sprintf("failed to verify selection: %v", err)
} else if currentValue.Str() == interaction.Value {
interactionResult.Success = true
} else {
interactionResult.Error = fmt.Sprintf("failed to select option: %s (current value: %s)", interaction.Value, currentValue.Str())
}
// Execute JavaScript and ignore any rod evaluation quirks
page.Eval(script)
// Always verify success by checking the element's actual value
currentValue, err := element.Property("value")
if err != nil {
interactionResult.Error = fmt.Sprintf("failed to verify selection: %v", err)
} else if currentValue.Str() == interaction.Value {
interactionResult.Success = true
} 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 {
interactionResult.Success = true