grafana/k6 · error
missing required argument 'text'
Error message
missing required argument 'text'
What it means
Thrown by locator.getByText() in the k6 browser module (internal/js/modules/k6/browser/browser/locator_mapping.go:281). The text argument (string or RegExp matched against element text content) is mandatory; the nullish guard fails the call before parseGetByBaseOptions builds the selector, since there is no way to query 'text of nothing'.
Solutions
- Pass a string or RegExp: page.locator('ul').getByText('Item 1')
- Default dynamic values: const label = row.label ?? 'Item 1'
- If the text is genuinely optional, branch instead of calling: if (label) child = parent.getByText(label)
- Trace where the variable becomes undefined (console.log or k6 console.debug) and fix the producer
Example fix
// before
const item = page.locator('ul').getByText(getLabel(i)); // getLabel returns undefined for some i
// after
const item = page.locator('ul').getByText(getLabel(i) ?? `Item ${i}`); Defensive patterns
Strategy: validation
Validate before calling
const label = getLabel(i) ?? `Item ${i}`;
if (label === undefined || label === null) throw new Error('text is required');
const loc = parent.getByText(label); Type guard
function isNonEmptyStringOrRegExp(v) {
return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;
}
// usage: if (!isNonEmptyStringOrRegExp(label)) throw new Error('text must be a non-empty string or RegExp'); Try / catch
try {
const loc = parent.getByText(label);
} catch (e) {
if (/missing required argument 'text'/.test(e.message)) throw new Error(`text missing for row ${i}`);
throw e;
} Prevention
- Check the producer of the text value (textContent, i18n lookup) before the call
- Branch when the text filter is optional instead of passing undefined
- Default dynamic labels with ??
- Assert fixture text fields exist once at script init
When it happens
Trigger: Calling parent.getByText() with zero arguments; passing undefined/null explicitly; passing a text variable computed from a function that returned undefined (e.g. missing .textContent).
Common situations: Labels/assertion strings read from i18n bundles or data files with missing keys; text extracted from a previous DOM node that did not exist; scripts parameterized so that some rows have no text filter.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- missing required argument 'placeholder'
- missing required argument 'role'
- missing required argument 'testId'
- missing required argument 'text'
- missing required argument 'title'
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/b59456b303b9e34e.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/locator_mapping.go:282
return nil, errors.New("missing required argument 'role'")
}
popts := parseGetByRoleOptions(vu.Context(), opts)
ml := mapLocator(vu, lo.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, lo.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, lo.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, lo.GetByTitle(ptitle, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"locator": func(selector string, opts sobek.Value) mapping {
return mapLocator(vu, lo.Locator(selector, parseLocatorOptions(rt, opts)))
},View on GitHub (pinned to 8d06114777)