grafana/k6 · error
counting elements
Error message
counting elements: %w
What it means
Returned by Frame.count when evaluating the injected count script on the document handle fails. The wrap adds operation context; the wrapped error is the evaluation failure (context destroyed, CDP error). The count itself cannot fail for 'no matches' — that returns 0.
Solutions
- Retry after the page/frame stabilizes
- Inspect the wrapped evaluation error
- Ensure the frame is not navigating while counting
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/frame.go:641 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/1e44d0a059147547.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/frame.go:649
)
if _, err := call(f.ctx, act, opts.Timeout); err != nil {
return errorFromDOMError(err)
}
return nil
}
func (f *Frame) count(selector string) (int, error) {
f.log.Debugf("Frame:count", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)
document, err := f.document()
if err != nil {
return 0, fmt.Errorf("getting document: %w", err)
}
c, err := document.count(f.ctx, selector)
if err != nil {
return 0, fmt.Errorf("counting elements: %w", err)
}
return c, nil
}
// Check clicks the first element found that matches selector.
func (f *Frame) Check(selector string, popts *FrameCheckOptions) error {
f.log.Debugf("Frame:Check", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)
if err := f.check(selector, popts); err != nil {
return fmt.Errorf("checking %q: %w", selector, err)
}
applySlowMo(f.ctx)
return nil
}
View on GitHub (pinned to 3fcf5388d7)