This commit is contained in:
Josh at WLTechBlog 2025-08-19 10:00:00 -05:00
parent af2a0584de
commit 8fc4f76b28
1 changed files with 24 additions and 14 deletions

View File

@ -3583,15 +3583,20 @@ 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, use JavaScript as fallback // If text selection failed, use JavaScript as fallback
// Use double quotes for the JavaScript string so single quotes in selectors work // Execute the value assignment (ignore evaluation errors, rod has issues with some JS patterns)
script := fmt.Sprintf("document.querySelector(\"%s\").value = \"%s\"; document.querySelector(\"%s\").dispatchEvent(new Event(\"change\", { bubbles: true })); document.querySelector(\"%s\").value", interaction.Selector, interaction.Value, interaction.Selector, interaction.Selector) script := fmt.Sprintf("document.querySelector(\"%s\").value = \"%s\"", interaction.Selector, interaction.Value)
page.Eval(script)
// Execute JavaScript and get the result // Dispatch the change event separately
result, err := page.Eval(script) changeScript := fmt.Sprintf("document.querySelector(\"%s\").dispatchEvent(new Event(\"change\", { bubbles: true }))", interaction.Selector)
page.Eval(changeScript)
// Verify the selection worked by checking the element's value property directly
currentValue, err := element.Property("value")
if err != nil { if err != nil {
interactionResult.Error = fmt.Sprintf("failed to execute JavaScript selection: %v", err) interactionResult.Error = fmt.Sprintf("failed to verify selection: %v", err)
} else if result.Value.Nil() || result.Value.String() == "" { } else if currentValue.Str() != interaction.Value {
interactionResult.Error = fmt.Sprintf("failed to select option '%s'", interaction.Value) interactionResult.Error = fmt.Sprintf("failed to select option '%s' (current value: %s)", interaction.Value, currentValue.Str())
} else { } else {
interactionResult.Success = true interactionResult.Success = true
} }
@ -3781,16 +3786,21 @@ func (d *Daemon) fillFormBulk(tabID, formSelector, fieldsJSON string, timeout in
err = element.Select([]string{fieldValue}, true, rod.SelectorTypeText) err = element.Select([]string{fieldValue}, true, rod.SelectorTypeText)
if err != nil { if err != nil {
// If text selection failed, use JavaScript as fallback // If text selection failed, use JavaScript as fallback
// Use double quotes for the JavaScript string so single quotes in selectors work // Execute the value assignment (ignore evaluation errors, rod has issues with some JS patterns)
script := fmt.Sprintf("document.querySelector(\"%s\").value = \"%s\"; document.querySelector(\"%s\").dispatchEvent(new Event(\"change\", { bubbles: true })); document.querySelector(\"%s\").value", fieldResult.Selector, fieldValue, fieldResult.Selector, fieldResult.Selector) script := fmt.Sprintf("document.querySelector(\"%s\").value = \"%s\"", fieldResult.Selector, fieldValue)
page.Eval(script)
// Execute JavaScript and get the result // Dispatch the change event separately
jsResult, err := page.Eval(script) changeScript := fmt.Sprintf("document.querySelector(\"%s\").dispatchEvent(new Event(\"change\", { bubbles: true }))", fieldResult.Selector)
page.Eval(changeScript)
// Verify the selection worked by checking the element's value property directly
currentValue, err := element.Property("value")
if err != nil { if err != nil {
fieldResult.Error = fmt.Sprintf("failed to execute JavaScript selection: %v", err) fieldResult.Error = fmt.Sprintf("failed to verify selection: %v", err)
result.ErrorCount++ result.ErrorCount++
} else if jsResult.Value.Nil() || jsResult.Value.String() == "" { } else if currentValue.Str() != fieldValue {
fieldResult.Error = fmt.Sprintf("failed to select option '%s'", fieldValue) fieldResult.Error = fmt.Sprintf("failed to select option '%s' (current value: %s)", fieldValue, currentValue.Str())
result.ErrorCount++ result.ErrorCount++
} else { } else {
fieldResult.Success = true fieldResult.Success = true