bump
This commit is contained in:
parent
36adab7878
commit
bfbda8e6a3
|
@ -1964,16 +1964,27 @@ func (d *Daemon) selectElement(tabID, selector, value string, selectionTimeout,
|
||||||
// Try to select by text first (most common case)
|
// Try to select by text first (most common case)
|
||||||
err = element.Select([]string{value}, true, rod.SelectorTypeText)
|
err = element.Select([]string{value}, true, rod.SelectorTypeText)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If text selection failed, the value might be the actual option value
|
// If text selection failed, use JavaScript as fallback
|
||||||
// Try to find and select by matching option value using page.Eval
|
// This handles both option value and option text selection
|
||||||
script := fmt.Sprintf(`(function(){ var el = document.querySelector("%s"); if(el) { el.value = "%s"; el.dispatchEvent(new Event('change', { bubbles: true })); } })()`, selector, value)
|
script := fmt.Sprintf(`(function(){
|
||||||
// Execute JavaScript and ignore any rod evaluation quirks
|
var el = document.querySelector("%s");
|
||||||
page.Eval(script)
|
if(el) {
|
||||||
|
el.value = "%s";
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
|
return el.value;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})()`, selector, value)
|
||||||
|
|
||||||
// Verify the selection worked by checking the value
|
// Execute JavaScript and get the result
|
||||||
actualValue, err := element.Attribute("value")
|
result, err := page.Eval(script)
|
||||||
if err != nil || actualValue == nil || *actualValue != value {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to select option '%s' in element", value)
|
return fmt.Errorf("failed to execute JavaScript selection: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if JavaScript selection worked
|
||||||
|
if result.Value.String() != value {
|
||||||
|
return fmt.Errorf("failed to select option '%s' in element (JavaScript fallback failed)", value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue