bump
This commit is contained in:
parent
e6ecf4eb06
commit
5d5be7e1a9
|
@ -1965,17 +1965,31 @@ func (d *Daemon) selectElement(tabID, selector, value string, selectionTimeout,
|
|||
err = element.Select([]string{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", selector, value, selector, selector)
|
||||
// Use a simple single statement that works with rod's evaluation
|
||||
script := fmt.Sprintf("document.querySelector(\"%s\").value = \"%s\"", selector, value)
|
||||
|
||||
// Execute JavaScript and get the result
|
||||
result, err := page.Eval(script)
|
||||
// Execute the value assignment
|
||||
_, err = page.Eval(script)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute JavaScript selection: %w", err)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// Verify the selection worked
|
||||
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
|
||||
if result.Value.Nil() || result.Value.String() == "" {
|
||||
if result.Value.Nil() || result.Value.String() != value {
|
||||
return fmt.Errorf("failed to select option '%s' in element", value)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue