grafana/k6 · error

focusing on

Error message

focusing on %q: %w

What it means

Wrapped failure from Frame.focus while focusing the element matched by the locator's selector (strict mode forced). Fires when the selector matches nothing or multiple elements, the element is not focusable or is hidden, or the CDP focus call fails.

Solutions

  1. Use a selector that uniquely matches a focusable element
  2. Ensure the element is visible and not disabled before focusing
  3. Retry after a short wait if the page is still rendering
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/locator.go:342 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/811c5a9b6acde7f0. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/locator.go:342

// Filter returns a new [Locator] after applying the options to the current one.
func (l *Locator) Filter(opts *LocatorFilterOptions) *Locator {
	return NewLocator(l.ctx, opts.LocatorOptions, l.selector, l.frame, l.log)
}

// First will return the first child of the element matching the locator's
// selector.
func (l *Locator) First() *Locator {
	return NewLocator(l.ctx, nil, l.selector+" >> nth=0", l.frame, l.log)
}

// Focus on the element using locator's selector with strict mode on.
func (l *Locator) Focus(opts *FrameBaseOptions) error {
	l.log.Debugf("Locator:Focus", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts)

	opts.Strict = true
	if err := l.frame.focus(l.selector, opts); err != nil {
		return fmt.Errorf("focusing on %q: %w", l.selector, err)
	}

	applySlowMo(l.ctx)

	return nil
}

// GetAttribute of the element using locator's selector with strict mode on.
// The second return value is true if the attribute exists, and false otherwise.
func (l *Locator) GetAttribute(name string, opts *FrameBaseOptions) (string, bool, error) {
	l.log.Debugf(
		"Locator:GetAttribute", "fid:%s furl:%q sel:%q name:%q opts:%+v",
		l.frame.ID(), l.frame.URL(), l.selector, name, opts,
	)

	opts.Strict = true
	s, ok, err := l.frame.getAttribute(l.selector, name, opts)
	if err != nil {

View on GitHub (pinned to 01ffac6f24)