This commit is contained in:
Josh at WLTechBlog 2025-08-18 14:00:33 -05:00
parent f96d344020
commit 0f3b287591
1 changed files with 3 additions and 26 deletions

View File

@ -3492,34 +3492,11 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) (
} }
case "select": case "select":
// For select elements, use JavaScript to set the value // For select elements, set the value using JavaScript
script := fmt.Sprintf(` script := fmt.Sprintf("this.value = '%s'; this.dispatchEvent(new Event('change', { bubbles: true })); true", interaction.Value)
(function() {
if (this.tagName.toLowerCase() === 'select') {
// Try to select by value first
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 }));
return true;
}
}
// Try to select by text if value didn't work
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 false;
}).call(this)
`, interaction.Value, interaction.Value, interaction.Value)
result, err := element.Eval(script) result, err := element.Eval(script)
if err != nil { if err != nil {
interactionResult.Error = fmt.Sprintf("failed to execute select script: %v", err) interactionResult.Error = fmt.Sprintf("failed to select option: %v", err)
} else if result.Value.Bool() { } else if result.Value.Bool() {
interactionResult.Success = true interactionResult.Success = true
} else { } else {