grafana/k6 · error
missing required argument 'text'
Error message
missing required argument 'text'
What it means
FrameLocator.getByText(text) in the k6 browser module requires a non-nullish first argument; the mapping layer throws before any browser communication. The text (string or RegExp) is the locator's only search criterion for finding elements by their text content, with options only refining matching behavior. Playwright's getByText has the same mandatory argument.
Source
Thrown at internal/js/modules/k6/browser/browser/frame_locator_mapping.go:62
return nil, errors.New("missing required argument 'role'")
}
popts := parseGetByRoleOptions(vu.Context(), opts)
ml := mapLocator(vu, fl.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, fl.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, fl.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, fl.GetByTitle(ptitle, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"locator": func(selector string, opts sobek.Value) mapping {
return mapLocator(vu, fl.Locator(selector, parseLocatorOptions(rt, opts)))
},View on GitHub (pinned to 93accf6570)
Solutions
- Pass the text string or RegExp: frameLocator.getByText('Welcome back')
- Default or validate content/i18n-sourced values before the call (const text = i18n.welcome ?? 'Welcome')
- Fix the undefined variable or missing translation key
- For fuzzy matches use a RegExp, e.g. getByText(/welcome/i), instead of omitting the argument
Example fix
// before
const msg = page.frameLocator('#frame').getByText(welcomeKey); // welcomeKey is undefined
// after
const welcomeKey = 'Welcome back';
const msg = page.frameLocator('#frame').getByText(welcomeKey); Defensive patterns
Strategy: validation
Validate before calling
const text = expected.welcome;
if (!isTextSelector(text)) throw new Error('expected.welcome is required for getByText');
frameLocator.getByText(text); Type guard
function isTextSelector(v) {
return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;
} Try / catch
try {
loc = frameLocator.getByText(maybeText);
} catch (e) {
if (/missing required argument 'text'/.test(String(e.message))) {
throw new Error(`expected text missing; fixture key='${key}'`);
}
throw e;
} Prevention
- Validate assertion fixtures at script start rather than mid-iteration
- Prefer ?? defaults on i18n/content lookups so text is never undefined at the call site
- Lint getBy* call sites for empty argument lists
- Log the resolved text once per scenario to make data gaps obvious in output
When it happens
Trigger: Calling page.frameLocator('iframe').getByText(), passing null/undefined explicitly, or passing a text variable that is undefined because the content fixture or i18n lookup returned nothing.
Common situations: Assertion helpers that receive an optional message parameter, localized-content tests with missing translation keys, or template literals that evaluate to undefined.
Related errors
- missing required argument 'altText'
- missing required argument 'label'
- missing required argument 'placeholder'
- missing required argument 'role'
- missing required argument 'testId'
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/73d59bfcabc52054.
Report an issue: GitHub.