bump
This commit is contained in:
parent
8fc4f76b28
commit
63860db70b
|
@ -3698,70 +3698,29 @@ func (d *Daemon) fillFormBulk(tabID, formSelector, fieldsJSON string, timeout in
|
|||
Success: false,
|
||||
}
|
||||
|
||||
// Try different selector strategies for the field
|
||||
// Try different selector strategies for the field (fast, no individual timeouts)
|
||||
var element *rod.Element
|
||||
var selectors []string
|
||||
selectors := []string{
|
||||
fmt.Sprintf("[name='%s']", fieldName),
|
||||
fmt.Sprintf("#%s", fieldName),
|
||||
fmt.Sprintf("[id='%s']", fieldName),
|
||||
fieldName, // In case it's already a full selector
|
||||
}
|
||||
|
||||
// If we have a form, search within it first
|
||||
// Search for element (try form first if available, then page)
|
||||
for _, selector := range selectors {
|
||||
// Try without timeout first (should be instant if element exists)
|
||||
if form != nil {
|
||||
selectors = []string{
|
||||
fmt.Sprintf("[name='%s']", fieldName),
|
||||
fmt.Sprintf("#%s", fieldName),
|
||||
fmt.Sprintf("[id='%s']", fieldName),
|
||||
fieldName, // In case it's already a full selector
|
||||
}
|
||||
|
||||
for _, selector := range selectors {
|
||||
if timeout > 0 {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
|
||||
element, err = form.Context(ctx).Element(selector)
|
||||
if err == nil {
|
||||
fieldResult.Selector = selector
|
||||
cancel() // Cancel context now that we found the element
|
||||
break
|
||||
}
|
||||
cancel() // Cancel if element not found
|
||||
} else {
|
||||
element, err = form.Element(selector)
|
||||
if err == nil {
|
||||
fieldResult.Selector = selector
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If not found in form or no form, search in entire page
|
||||
if element == nil {
|
||||
// Generate selectors if not already done
|
||||
if selectors == nil {
|
||||
selectors = []string{
|
||||
fmt.Sprintf("[name='%s']", fieldName),
|
||||
fmt.Sprintf("#%s", fieldName),
|
||||
fmt.Sprintf("[id='%s']", fieldName),
|
||||
fieldName, // In case it's already a full selector
|
||||
}
|
||||
}
|
||||
|
||||
for _, selector := range selectors {
|
||||
if timeout > 0 {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
|
||||
element, err = page.Context(ctx).Element(selector)
|
||||
if err == nil {
|
||||
fieldResult.Selector = selector
|
||||
cancel() // Cancel context now that we found the element
|
||||
break
|
||||
}
|
||||
cancel() // Cancel if element not found
|
||||
} else {
|
||||
element, err = page.Element(selector)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
fieldResult.Selector = selector
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if element == nil {
|
||||
fieldResult.Error = fmt.Sprintf("failed to find field: %s", fieldName)
|
||||
|
@ -3770,8 +3729,8 @@ func (d *Daemon) fillFormBulk(tabID, formSelector, fieldsJSON string, timeout in
|
|||
continue
|
||||
}
|
||||
|
||||
// Determine the element type and use appropriate action
|
||||
tagName, err := element.Eval("() => this.tagName.toLowerCase()")
|
||||
// Determine the element type using rod's built-in method (much faster than Eval)
|
||||
tagName, err := element.Property("tagName")
|
||||
if err != nil {
|
||||
fieldResult.Error = fmt.Sprintf("failed to get element tag name: %v", err)
|
||||
result.FilledFields = append(result.FilledFields, fieldResult)
|
||||
|
@ -3780,7 +3739,7 @@ func (d *Daemon) fillFormBulk(tabID, formSelector, fieldsJSON string, timeout in
|
|||
}
|
||||
|
||||
// Handle different element types
|
||||
if tagName.Value.String() == "select" {
|
||||
if strings.ToLower(tagName.Str()) == "select" {
|
||||
// Use select action for select elements
|
||||
fieldResult.Action = "select"
|
||||
err = element.Select([]string{fieldValue}, true, rod.SelectorTypeText)
|
||||
|
|
Loading…
Reference in New Issue