grafana/k6 · error
parsing element index %q for selector %q: %w
Error message
parsing element index %q for selector %q: %w
What it means
While flattening the $$ result, queryAll iterates GetProperties of the array-like handle and expects numeric keys ('0','1',...); strconv.Atoi rejected a key (element_handle.go:1308). Per JavaScript array semantics the keys must be indices, so a non-numeric key means the protocol returned a non-array-like shape — an internal/k6 bug, not user input.
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 93accf6570)
Solutions
- Upgrade k6 to the latest release
- If it persists, file a k6 issue with the minimal selector and chromium version
- Work around with page.$$ or frame.$$ on the containing frame
- Avoid the affected element.$$ path while the bug is outstanding
Defensive patterns
Strategy: try-catch
Try / catch
try { return await el.$$(sel); }
catch (e) { if (/parsing element index/.test(e.message)) { return await page.$$(sel); /* fallback path */ } throw e; } Prevention
- Treat as an internal bug: update k6, report upstream
- Keep a page.$$ fallback for scraping paths
When it happens
Trigger: GetProperties returning symbol/named properties or an unexpected object shape from a chromium version deviation; k6 browser-module regression in the $$ plumbing.
Common situations: Not seen in normal use; surfaces with unusual chromium builds or module regressions, consistently for the same selector.
Related errors
- querying selector %q, wrong type %T
- getting element handle for selector %q: %w
- unpacking selected options: %w
- getting text content of element: unexpected type %T (expecti
- unexpected DOM error type %T
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/2ae777cb908fe416.
Report an issue: GitHub.