multiple
This commit is contained in:
parent
62acebe8c6
commit
ba5d7f428f
|
@ -3492,39 +3492,23 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) (
|
||||||
}
|
}
|
||||||
|
|
||||||
case "select":
|
case "select":
|
||||||
// For select elements, use page.Eval instead of element.Eval to avoid apply issues
|
// For select elements, use rod's built-in Select method
|
||||||
script := fmt.Sprintf(`
|
// Try to select by text first (most common case)
|
||||||
(() => {
|
err = element.Select([]string{interaction.Value}, true, rod.SelectorTypeText)
|
||||||
const element = document.querySelector("%s");
|
|
||||||
if (element && element.tagName.toLowerCase() === 'select') {
|
|
||||||
// Try to select by value first
|
|
||||||
for (let option of element.options) {
|
|
||||||
if (option.value === "%s") {
|
|
||||||
element.value = "%s";
|
|
||||||
element.dispatchEvent(new Event('change', { bubbles: true }));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Try to select by text if value didn't work
|
|
||||||
for (let option of element.options) {
|
|
||||||
if (option.text === "%s") {
|
|
||||||
element.value = option.value;
|
|
||||||
element.dispatchEvent(new Event('change', { bubbles: true }));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
})()
|
|
||||||
`, interaction.Selector, interaction.Value, interaction.Value, interaction.Value)
|
|
||||||
|
|
||||||
result, err := page.Eval(script)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
interactionResult.Error = fmt.Sprintf("failed to select option: %v", err)
|
// If text selection failed, the value might be the actual option value
|
||||||
} else if result.Value.Bool() {
|
// Try to find and select by matching option value using JavaScript
|
||||||
interactionResult.Success = true
|
script := fmt.Sprintf("this.value = '%s'", interaction.Value)
|
||||||
|
_, jsErr := element.Eval(script)
|
||||||
|
if jsErr == nil {
|
||||||
|
// Trigger change event
|
||||||
|
_, _ = element.Eval("this.dispatchEvent(new Event('change', { bubbles: true }))")
|
||||||
|
interactionResult.Success = true
|
||||||
|
} else {
|
||||||
|
interactionResult.Error = fmt.Sprintf("failed to select option: %v", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
interactionResult.Error = fmt.Sprintf("failed to select option: %s", interaction.Value)
|
interactionResult.Success = true
|
||||||
}
|
}
|
||||||
|
|
||||||
case "check":
|
case "check":
|
||||||
|
|
Loading…
Reference in New Issue