This commit is contained in:
Josh at WLTechBlog 2025-08-18 14:13:37 -05:00
parent 3561bd1f01
commit ae7b92dec1
1 changed files with 31 additions and 11 deletions

View File

@ -3492,20 +3492,40 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) (
} }
case "select": case "select":
// For select elements, set the value using JavaScript // For select elements, use page.Eval instead of element.Eval to avoid apply issues
script := fmt.Sprintf("this.value = '%s'", interaction.Value) script := fmt.Sprintf(`
_, err := element.Eval(script) (() => {
if err != nil { const element = document.querySelector('%s');
interactionResult.Error = fmt.Sprintf("failed to set select value: %v", err) if (element && element.tagName.toLowerCase() === 'select') {
} else { // Try to select by value first
// Trigger change event for (let option of element.options) {
_, err = element.Eval("this.dispatchEvent(new Event('change', { bubbles: true }))") if (option.value === '%s') {
if err != nil { element.value = '%s';
interactionResult.Error = fmt.Sprintf("failed to trigger change event: %v", err) element.dispatchEvent(new Event('change', { bubbles: true }));
} else { return true;
interactionResult.Success = 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 {
interactionResult.Error = fmt.Sprintf("failed to select option: %v", err)
} else if result.Value.Bool() {
interactionResult.Success = true
} else {
interactionResult.Error = fmt.Sprintf("failed to select option: %s", interaction.Value)
}
case "check": case "check":
// Check if it's already checked // Check if it's already checked