grafana/k6 · error

getting attribute of

Error message

getting attribute %q of %q: %w

What it means

Wrapped failure from Frame.getAttribute while reading the named attribute of the element matched by the locator's selector (strict mode forced). Fires on selector mismatch (zero/multiple matches), element detachment, or a failed CDP attribute lookup. A missing attribute returns empty/false, not this error.

Solutions

  1. Refine the selector to match exactly one element
  2. Ensure the element is still attached when the read happens
  3. Check the boolean return for absence instead of relying on an error
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/locator.go:361 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/ff262c0689a0068f. Report an issue: GitHub.

Appendix: source

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

	}

	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 {
		return "", false, fmt.Errorf("getting attribute %q of %q: %w", name, l.selector, err)
	}

	return s, ok, nil
}

// GetByAltText creates and returns a new relative locator that allows locating elements by their alt text.
func (l *Locator) GetByAltText(alt string, opts *GetByBaseOptions) *Locator {
	l.log.Debugf(
		"Locator:GetByAltText", "fid:%s furl:%q selector:%s alt:%q opts:%+v",
		l.frame.ID(), l.frame.URL(), l.selector, alt, opts,
	)

	return l.Locator(l.frame.buildAttributeSelector("alt", alt, opts), nil)
}

// GetByLabel creates and returns a new relative locator that allows locating input elements by the text
// of the associated `<label>` or `aria-labelledby` element, or by the `aria-label` attribute.
func (l *Locator) GetByLabel(label string, opts *GetByBaseOptions) *Locator {

View on GitHub (pinned to 01ffac6f24)