This commit is contained in:
Josh at WLTechBlog 2025-08-19 09:51:54 -05:00
parent 5d5be7e1a9
commit a69560849c
1 changed files with 5 additions and 11 deletions

View File

@ -1968,27 +1968,21 @@ func (d *Daemon) selectElement(tabID, selector, value string, selectionTimeout,
// Use a simple single statement that works with rod's evaluation
script := fmt.Sprintf("document.querySelector(\"%s\").value = \"%s\"", selector, value)
// Execute the value assignment
_, err = page.Eval(script)
if err != nil {
return fmt.Errorf("failed to execute JavaScript selection: %w", err)
}
// Execute the value assignment (ignore evaluation errors, rod has issues with some JS patterns)
page.Eval(script)
// Dispatch the change event separately
changeScript := fmt.Sprintf("document.querySelector(\"%s\").dispatchEvent(new Event(\"change\", { bubbles: true }))", selector)
_, err = page.Eval(changeScript)
if err != nil {
return fmt.Errorf("failed to dispatch change event: %w", err)
}
page.Eval(changeScript)
// Verify the selection worked
// Verify the selection worked by checking the actual element value
verifyScript := fmt.Sprintf("document.querySelector(\"%s\").value", selector)
result, err := page.Eval(verifyScript)
if err != nil {
return fmt.Errorf("failed to verify selection: %w", err)
}
// Verify the selection worked by checking the returned value
// Check if the selection actually worked
if result.Value.Nil() || result.Value.String() != value {
return fmt.Errorf("failed to select option '%s' in element", value)
}