multiple
This commit is contained in:
parent
166deca9f9
commit
f96d344020
|
@ -3494,44 +3494,36 @@ 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, use JavaScript to set the value
|
||||||
script := fmt.Sprintf(`
|
script := fmt.Sprintf(`
|
||||||
(() => {
|
(function() {
|
||||||
if (this.tagName.toLowerCase() === 'select') {
|
if (this.tagName.toLowerCase() === 'select') {
|
||||||
// Try to select by value first
|
// Try to select by value first
|
||||||
for (let option of this.options) {
|
for (var i = 0; i < this.options.length; i++) {
|
||||||
if (option.value === '%s') {
|
if (this.options[i].value === '%s') {
|
||||||
this.value = '%s';
|
this.value = '%s';
|
||||||
this.dispatchEvent(new Event('change', { bubbles: true }));
|
this.dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
break;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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 (var i = 0; i < this.options.length; i++) {
|
||||||
for (let option of this.options) {
|
if (this.options[i].text === '%s') {
|
||||||
if (option.text === '%s') {
|
this.value = this.options[i].value;
|
||||||
this.value = option.value;
|
this.dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
this.dispatchEvent(new Event('change', { bubbles: true }));
|
return true;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
})()
|
}).call(this)
|
||||||
`, interaction.Value, interaction.Value, interaction.Value, interaction.Value)
|
`, interaction.Value, interaction.Value, interaction.Value)
|
||||||
|
|
||||||
_, 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 execute select script: %v", err)
|
||||||
|
} else if result.Value.Bool() {
|
||||||
|
interactionResult.Success = true
|
||||||
} else {
|
} else {
|
||||||
// Check if the value was actually set
|
interactionResult.Error = fmt.Sprintf("failed to select option: %s", interaction.Value)
|
||||||
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":
|
case "check":
|
||||||
|
|
Loading…
Reference in New Issue