multiple
This commit is contained in:
parent
dd55c67ad4
commit
439ae4b5f7
|
@ -3497,13 +3497,16 @@ 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, the value might be the actual option value
|
||||
// Try to find and select by matching option value using JavaScript
|
||||
script := fmt.Sprintf("this.value = '%s'", interaction.Value)
|
||||
_, jsErr := element.Eval(script)
|
||||
// Try to find and select by matching option value using page.Eval to avoid element.Eval issues
|
||||
script := fmt.Sprintf(`
|
||||
const element = document.querySelector("%s");
|
||||
if (element) {
|
||||
element.value = "%s";
|
||||
element.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
`, interaction.Selector, interaction.Value)
|
||||
_, jsErr := page.Eval(script)
|
||||
if jsErr == nil {
|
||||
// Trigger change event
|
||||
_, _ = element.Eval("this.dispatchEvent(new Event('change', { bubbles: true }))")
|
||||
|
||||
// Verify the JavaScript selection worked by checking the element's value
|
||||
currentValue, err := element.Property("value")
|
||||
if err != nil {
|
||||
|
@ -3514,7 +3517,7 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) (
|
|||
interactionResult.Error = fmt.Sprintf("failed to select option: %s (current value: %s)", interaction.Value, currentValue.Str())
|
||||
}
|
||||
} else {
|
||||
interactionResult.Error = fmt.Sprintf("failed to select option: %v", err)
|
||||
interactionResult.Error = fmt.Sprintf("failed to select option: %v", jsErr)
|
||||
}
|
||||
} else {
|
||||
interactionResult.Success = true
|
||||
|
|
Loading…
Reference in New Issue