From ae7b92dec14d8bf6dfc7ccd85cf60cf320efabf9 Mon Sep 17 00:00:00 2001 From: Josh at WLTechBlog Date: Mon, 18 Aug 2025 14:13:37 -0500 Subject: [PATCH] multiple --- daemon/daemon.go | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 2646b64..e266464 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -3492,19 +3492,39 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) ( } case "select": - // For select elements, set the value using JavaScript - script := fmt.Sprintf("this.value = '%s'", interaction.Value) - _, err := element.Eval(script) + // For select elements, use page.Eval instead of element.Eval to avoid apply issues + script := fmt.Sprintf(` + (() => { + 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 { - interactionResult.Error = fmt.Sprintf("failed to set select value: %v", err) + interactionResult.Error = fmt.Sprintf("failed to select option: %v", err) + } else if result.Value.Bool() { + interactionResult.Success = true } else { - // Trigger change event - _, err = element.Eval("this.dispatchEvent(new Event('change', { bubbles: true }))") - if err != nil { - interactionResult.Error = fmt.Sprintf("failed to trigger change event: %v", err) - } else { - interactionResult.Success = true - } + interactionResult.Error = fmt.Sprintf("failed to select option: %s", interaction.Value) } case "check":