grafana/k6 · error
missing required argument 'text'
Error message
missing required argument 'text'
What it means
Thrown by the Page mapping's getByText method. The text to match is mandatory; the mapping validates it with k6common.IsNullish, then parses string/RegExp plus options (exact/substring) via parseGetByBaseOptions before calling p.GetByText. Nullish input never becomes a locator.
Source
Thrown at internal/js/modules/k6/browser/browser/page_mapping.go:227
return nil, errors.New("missing required argument 'title'")
}
ptitle, popts := parseGetByBaseOptions(vu.Context(), title, false, opts)
ml := mapLocator(vu, p.GetByTitle(ptitle, 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, p.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, p.GetByText(ptext, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"goto": func(url string, opts sobek.Value) (*sobek.Promise, error) {
gopts := common.NewFrameGotoOptions(
p.Referrer(),
p.NavigationTimeout(),
)
if err := gopts.Parse(vu.Context(), opts); err != nil {
return nil, fmt.Errorf("parsing page navigation options to %q: %w", url, err)
}
return promise(vu, func() (any, error) {
resp, err := p.Goto(url, gopts)
if err != nil {
return nil, err //nolint:wrapcheckView on GitHub (pinned to 93accf6570)
Solutions
- Pass a string or RegExp: page.getByText('Welcome') or page.getByText(/welcome/i)
- Guard dynamic text: page.getByText(text ?? 'Welcome')
- In wrapper helpers, throw a specific error when the forwarded text is nullish so the failure points at your data, not the API
Example fix
// before
page.getByText();
// after
page.getByText('Welcome'); Defensive patterns
Strategy: validation
Validate before calling
if (text === undefined || text === null) {
throw new Error(`page.getByText: 'text' is required, got ${text}`);
}
const loc = page.getByText(text, opts); Type guard
function isTextMatcher(v) {
return typeof v === 'string' || v instanceof RegExp;
} Try / catch
try {
page.getByText(text);
} catch (e) {
if (!e.message.includes("missing required argument 'text'")) throw e;
throw new Error(`expected text value missing from data`);
} Prevention
- In wrapper helpers, make the text parameter required (TS) or assert it before forwarding
When it happens
Trigger: page.getByText() with no arguments; page.getByText(undefined) from unset data; passing only an options object as the first parameter.
Common situations: Assertion helpers that wrap getByText and forward optional parameters verbatim; empty fields in CSV-driven tests; Playwright example code trimmed during porting.
Related errors
- missing required argument 'text'
- missing required argument 'role'
- missing required argument 'altText'
- missing required argument 'label'
- missing required argument 'placeholder'
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/0bf0ab3ed3b98324.
Report an issue: GitHub.