grafana/k6 · error
parsing element index
Error message
parsing element index %q for selector %q: %w
What it means
Returned by ElementHandle.queryAll while iterating the properties of the query-result handle: a property key that maps to an element is expected to be a numeric index ('0','1',...), but strconv.Atoi failed for the given key. Indicates the injected script returned an object whose element-valued properties are not numerically indexed — an internal contract violation, not bad user input (the selector parsed fine).
Solutions
- Report as a k6 browser module bug with the selector and page that triggered it
- Retry with a different selector as a workaround
- Ensure page scripts do not tamper with array indices of results
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/element_handle.go:1308 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/2ae777cb908fe416.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:1308
props, err := handles.GetProperties()
if err != nil {
// GetProperties has a rich error already, so we don't need to wrap it.
return nil, err //nolint:wrapcheck
}
type indexedElem struct {
index int
elem *ElementHandle
}
indexedElems := make([]indexedElem, 0, len(props))
for key, prop := range props {
if el := prop.AsElement(); el != nil {
// DOM elements are stored with numeric indices ("0", "1", "2", ...)
// per JavaScript's array-like object specification.
idx, err := strconv.Atoi(key)
if err != nil {
return nil, fmt.Errorf("parsing element index %q for selector %q: %w", key, selector, err)
}
indexedElems = append(indexedElems, indexedElem{index: idx, elem: el})
} else if err := prop.Dispose(); err != nil {
return nil, fmt.Errorf("disposing property while querying all selectors %q: %w", selector, err)
}
}
slices.SortFunc(indexedElems, func(a, b indexedElem) int {
return cmp.Compare(a.index, b.index)
})
els := make([]*ElementHandle, 0, len(indexedElems))
for _, ie := range indexedElems {
els = append(els, ie.elem)
}
return els, nil
}View on GitHub (pinned to 3fcf5388d7)