This commit is contained in:
Josh at WLTechBlog 2025-08-18 13:53:03 -05:00
parent f888ab8026
commit 7fda3a32ed
1 changed files with 25 additions and 19 deletions

View File

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