grafana/k6 · error
missing required argument 'text'
Error message
missing required argument 'text'
What it means
Frame.getByText(text) on a k6 browser Frame requires a non-nullish first argument; the mapping in frame_mapping.go throws before any browser call. The text (string or RegExp) is the locator's only matching criterion for element text content; options only adjust matching semantics. Playwright's getByText is equally strict.
Source
Thrown at internal/js/modules/k6/browser/browser/frame_mapping.go:185
return nil, errors.New("missing required argument 'role'")
}
popts := parseGetByRoleOptions(vu.Context(), opts)
ml := mapLocator(vu, f.GetByRole(role.String(), popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByTestId": func(testID sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(testID) {
return nil, errors.New("missing required argument 'testId'")
}
ptestID := parseStringOrRegex(testID, false)
ml := mapLocator(vu, f.GetByTestID(ptestID))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByText": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(text) {
return nil, errors.New("missing required argument 'text'")
}
ptext, popts := parseGetByBaseOptions(vu.Context(), text, true, opts)
ml := mapLocator(vu, f.GetByText(ptext, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByTitle": func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(title) {
return nil, errors.New("missing required argument 'title'")
}
ptitle, popts := parseGetByBaseOptions(vu.Context(), title, false, opts)
ml := mapLocator(vu, f.GetByTitle(ptitle, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"goto": func(url string, opts sobek.Value) (*sobek.Promise, error) {
gopts := common.NewFrameGotoOptions(
f.Referrer(),View on GitHub (pinned to 93accf6570)
Solutions
- Pass the text string or RegExp: frame.getByText('Order confirmed')
- Default or validate content/i18n values before the call (const text = msg ?? 'Order confirmed')
- Fix the undefined variable or missing message key
- Use a RegExp for partial matching, e.g. frame.getByText(/confirmed/i), instead of omitting text
Example fix
// before
const ok = page.frame('#result').getByText(messageKey); // messageKey is undefined
// after
const messageKey = 'Order confirmed';
const ok = page.frame('#result').getByText(messageKey); Defensive patterns
Strategy: validation
Validate before calling
const text = expected[key];
if (!isTextSelector(text)) throw new Error(`expected[${key}] is required for getByText`);
frame.getByText(text); Type guard
function isTextSelector(v) {
return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;
} Try / catch
try {
loc = frame.getByText(maybeText);
} catch (e) {
if (/missing required argument 'text'/.test(String(e.message))) {
throw new Error(`text missing for expectation '${key}'`);
}
throw e;
} Prevention
- Validate expectation objects fully at script start; fail before any VU work
- Default i18n lookups with ?? so text is never undefined at call time
- Prefer RegExp partial matches over omitting text when wording varies
- Log resolved expected texts once to surface data gaps early
When it happens
Trigger: Calling frame.getByText() with no argument, passing null/undefined, or passing an expected-message variable that is undefined because the fixture or i18n bundle missed it.
Common situations: Content-verification helpers with optional message parameters, localized assertion strings, template literals referencing the wrong variable.
Related errors
- missing required argument 'text'
- missing required argument 'altText'
- missing required argument 'label'
- missing required argument 'placeholder'
- missing required argument 'role'
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/be3e21a32a9994c8.
Report an issue: GitHub.