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)
if err != nil {
// If text selection failed, use JavaScript as fallback
// Use double quotes for the JavaScript string so single quotes in selectors work
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)
// Execute the value assignment (ignore evaluation errors, rod has issues with some JS patterns)
script := fmt.Sprintf("document.querySelector(\"%s\").value = \"%s\"", interaction.Selector, interaction.Value)
page.Eval(script)
// Execute JavaScript and get the result
result, err := page.Eval(script)
// Dispatch the change event separately
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 {
interactionResult.Error = fmt.Sprintf("failed to execute JavaScript selection: %v", err)
} else if result.Value.Nil() || result.Value.String() == "" {
interactionResult.Error = fmt.Sprintf("failed to select option '%s'", interaction.Value)
interactionResult.Error = fmt.Sprintf("failed to verify selection: %v", err)
} else if currentValue.Str() != interaction.Value {
interactionResult.Error = fmt.Sprintf("failed to select option '%s' (current value: %s)", interaction.Value, currentValue.Str())
} else {
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)
if err != nil {
// If text selection failed, use JavaScript as fallback
// Use double quotes for the JavaScript string so single quotes in selectors work
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)
// Execute the value assignment (ignore evaluation errors, rod has issues with some JS patterns)
script := fmt.Sprintf("document.querySelector(\"%s\").value = \"%s\"", fieldResult.Selector, fieldValue)
page.Eval(script)
// Execute JavaScript and get the result
jsResult, err := page.Eval(script)
// Dispatch the change event separately
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 {
fieldResult.Error = fmt.Sprintf("failed to execute JavaScript selection: %v", err)
fieldResult.Error = fmt.Sprintf("failed to verify selection: %v", err)
result.ErrorCount++
} else if jsResult.Value.Nil() || jsResult.Value.String() == "" {
fieldResult.Error = fmt.Sprintf("failed to select option '%s'", fieldValue)
} else if currentValue.Str() != fieldValue {
fieldResult.Error = fmt.Sprintf("failed to select option '%s' (current value: %s)", fieldValue, currentValue.Str())
result.ErrorCount++
} else {
fieldResult.Success = true