grafana/k6 · error
focusing
Error message
focusing %q: %w
What it means
Returned by Frame.Focus when focusing the first matching element fails. Wrap-only: the underlying action error (element not attached within timeout, evaluation failure, CDP error) carries the real cause for the selector.
Solutions
- Ensure the selector matches an attached element
- Increase the timeout
- Retry after DOM changes; verify the element is focusable
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/frame.go:961 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/7a261c247cf3fb1b.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/frame.go:969
}
act := f.newAction(
selector, DOMElementStateAttached, opts.Strict,
fill, []string{"visible", "enabled", "editable"},
opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,
)
if _, err := call(f.ctx, act, opts.Timeout); err != nil {
return errorFromDOMError(err)
}
return nil
}
// Focus focuses on the first element that matches the selector.
func (f *Frame) Focus(selector string, popts *FrameBaseOptions) error {
f.log.Debugf("Frame:Focus", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)
if err := f.focus(selector, popts); err != nil {
return fmt.Errorf("focusing %q: %w", selector, err)
}
applySlowMo(f.ctx)
return nil
}
func (f *Frame) focus(selector string, opts *FrameBaseOptions) error {
focus := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
return nil, handle.focus(apiCtx, true)
}
act := f.newAction(
selector, DOMElementStateAttached, opts.Strict, focus,
[]string{}, false, withRetry, true, opts.Timeout,
)
if _, err := call(f.ctx, act, opts.Timeout); err != nil {
return errorFromDOMError(err)
}View on GitHub (pinned to 3fcf5388d7)