grafana/k6 · error
getting text content of
Error message
getting text content of %q: %w
What it means
Wrapped failure from Frame.textContent while reading the text content of the element matched by the locator's selector (strict mode forced). Fires when the selector matches zero or multiple elements, the node is detached, or the CDP textContent evaluation fails. Null/empty content returns ("", false, nil), not this error.
Solutions
- Use a selector that resolves to exactly one element
- Wait for the element to exist before reading its text
- Use the boolean flag to detect null content rather than expecting an error
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/locator.go:501 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/ba53fdb80e221b5c.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/locator.go:501
}
// Nth will return the nth child of the element matching the locator's
// selector.
func (l *Locator) Nth(nth int) *Locator {
return NewLocator(l.ctx, nil, l.selector+" >> nth="+strconv.Itoa(nth), l.frame, l.log)
}
// TextContent returns the element's text content that matches
// the locator's selector with strict mode on. The second return
// value is true if the returned text content is not null or empty,
// and false otherwise.
func (l *Locator) TextContent(opts *FrameTextContentOptions) (string, bool, error) {
l.log.Debugf("Locator:TextContent", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts)
opts.Strict = true
s, ok, err := l.frame.textContent(l.selector, opts)
if err != nil {
return "", false, fmt.Errorf("getting text content of %q: %w", l.selector, err)
}
return s, ok, nil
}
// InputValue returns the element's input value that matches
// the locator's selector with strict mode on.
func (l *Locator) InputValue(opts *FrameInputValueOptions) (string, error) {
l.log.Debugf("Locator:InputValue", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts)
opts.Strict = true
v, err := l.frame.inputValue(l.selector, opts)
if err != nil {
return "", fmt.Errorf("getting input value of %q: %w", l.selector, err)
}
return v, nil
}View on GitHub (pinned to 01ffac6f24)