diff --git a/daemon/daemon.go b/daemon/daemon.go index 0fc98ca..0af7cc2 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -3494,44 +3494,36 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) ( case "select": // For select elements, use JavaScript to set the value script := fmt.Sprintf(` - (() => { + (function() { if (this.tagName.toLowerCase() === 'select') { // Try to select by value first - for (let option of this.options) { - if (option.value === '%s') { + for (var i = 0; i < this.options.length; i++) { + if (this.options[i].value === '%s') { this.value = '%s'; this.dispatchEvent(new Event('change', { bubbles: true })); - break; + return true; } } // Try to select by text if value didn't work - if (this.value !== '%s') { - for (let option of this.options) { - if (option.text === '%s') { - this.value = option.value; - this.dispatchEvent(new Event('change', { bubbles: true })); - break; - } + for (var i = 0; i < this.options.length; i++) { + if (this.options[i].text === '%s') { + this.value = this.options[i].value; + this.dispatchEvent(new Event('change', { bubbles: true })); + return true; } } } - return true; - })() - `, interaction.Value, interaction.Value, interaction.Value, interaction.Value) + return false; + }).call(this) + `, interaction.Value, interaction.Value, interaction.Value) - _, err := element.Eval(script) + result, err := element.Eval(script) if err != nil { interactionResult.Error = fmt.Sprintf("failed to execute select script: %v", err) + } else if result.Value.Bool() { + interactionResult.Success = true } else { - // Check if the value was actually set - currentValue, err := element.Property("value") - if err != nil { - interactionResult.Error = fmt.Sprintf("failed to get current value: %v", err) - } else if currentValue.Str() == interaction.Value { - interactionResult.Success = true - } else { - interactionResult.Error = fmt.Sprintf("failed to select option: %s (current value: %s)", interaction.Value, currentValue.Str()) - } + interactionResult.Error = fmt.Sprintf("failed to select option: %s", interaction.Value) } case "check":