This commit is contained in:
Josh at WLTechBlog 2025-08-19 08:03:06 -05:00
parent 35a2ed62c7
commit e2e44b40e2
1 changed files with 6 additions and 75 deletions

View File

@ -1965,31 +1965,8 @@ func (d *Daemon) selectElement(tabID, selector, value string, selectionTimeout,
err = element.Select([]string{value}, true, rod.SelectorTypeText)
if err != nil {
// If text selection failed, use JavaScript as fallback
// This handles both option value and option text selection
script := fmt.Sprintf(`
var select = document.querySelector("%s");
var result = null;
if (select) {
// First try to select by value
select.value = "%s";
if (select.value === "%s") {
select.dispatchEvent(new Event('change', { bubbles: true }));
result = select.value;
} else {
// If value selection failed, try to find by text content
var options = select.options;
for (var i = 0; i < options.length; i++) {
if (options[i].text === "%s") {
select.selectedIndex = i;
select.dispatchEvent(new Event('change', { bubbles: true }));
result = select.value;
break;
}
}
}
}
result;
`, selector, value, value, value)
// Use a single-line approach that works with rod's evaluation
script := fmt.Sprintf(`(() => { const select = document.querySelector("%s"); if (!select) return null; select.value = "%s"; if (select.value === "%s") { select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } for (let i = 0; i < select.options.length; i++) { if (select.options[i].text === "%s") { select.selectedIndex = i; select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } } return null; })()`, selector, value, value, value)
// Execute JavaScript and get the result
result, err := page.Eval(script)
@ -3599,31 +3576,8 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) (
err = element.Select([]string{interaction.Value}, true, rod.SelectorTypeText)
if err != nil {
// If text selection failed, use JavaScript as fallback
// This handles both option value and option text selection
script := fmt.Sprintf(`
var select = document.querySelector("%s");
var result = null;
if (select) {
// First try to select by value
select.value = "%s";
if (select.value === "%s") {
select.dispatchEvent(new Event('change', { bubbles: true }));
result = select.value;
} else {
// If value selection failed, try to find by text content
var options = select.options;
for (var i = 0; i < options.length; i++) {
if (options[i].text === "%s") {
select.selectedIndex = i;
select.dispatchEvent(new Event('change', { bubbles: true }));
result = select.value;
break;
}
}
}
}
result;
`, interaction.Selector, interaction.Value, interaction.Value, interaction.Value)
// Use a single-line approach that works with rod's evaluation
script := fmt.Sprintf(`(() => { const select = document.querySelector("%s"); if (!select) return null; select.value = "%s"; if (select.value === "%s") { select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } for (let i = 0; i < select.options.length; i++) { if (select.options[i].text === "%s") { select.selectedIndex = i; select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } } return null; })()`, interaction.Selector, interaction.Value, interaction.Value, interaction.Value)
// Execute JavaScript and get the result
result, err := page.Eval(script)
@ -3820,31 +3774,8 @@ func (d *Daemon) fillFormBulk(tabID, formSelector, fieldsJSON string, timeout in
err = element.Select([]string{fieldValue}, true, rod.SelectorTypeText)
if err != nil {
// If text selection failed, use JavaScript as fallback
// This handles both option value and option text selection
script := fmt.Sprintf(`
var select = document.querySelector("%s");
var result = null;
if (select) {
// First try to select by value
select.value = "%s";
if (select.value === "%s") {
select.dispatchEvent(new Event('change', { bubbles: true }));
result = select.value;
} else {
// If value selection failed, try to find by text content
var options = select.options;
for (var i = 0; i < options.length; i++) {
if (options[i].text === "%s") {
select.selectedIndex = i;
select.dispatchEvent(new Event('change', { bubbles: true }));
result = select.value;
break;
}
}
}
}
result;
`, fieldResult.Selector, fieldValue, fieldValue, fieldValue)
// Use a single-line approach that works with rod's evaluation
script := fmt.Sprintf(`(() => { const select = document.querySelector("%s"); if (!select) return null; select.value = "%s"; if (select.value === "%s") { select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } for (let i = 0; i < select.options.length; i++) { if (select.options[i].text === "%s") { select.selectedIndex = i; select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } } return null; })()`, fieldResult.Selector, fieldValue, fieldValue, fieldValue)
// Execute JavaScript and get the result
jsResult, err := page.Eval(script)