grafana/k6 · error
missing required argument 'label'
Error message
missing required argument 'label'
What it means
Thrown by the Page mapping's getByLabel method. The label text is the mandatory first argument; the mapping checks it with k6common.IsNullish before calling p.GetByLabel with parsed base options (string or RegExp plus exact/substring options). Nullish input is rejected up front.
Source
Thrown at internal/js/modules/k6/browser/browser/page_mapping.go:191
return nil, errors.New("missing required argument 'role'")
}
popts := parseGetByRoleOptions(vu.Context(), opts)
ml := mapLocator(vu, p.GetByRole(role.String(), popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByAltText": func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(alt) {
return nil, errors.New("missing required argument 'altText'")
}
palt, popts := parseGetByBaseOptions(vu.Context(), alt, false, opts)
ml := mapLocator(vu, p.GetByAltText(palt, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByLabel": func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(label) {
return nil, errors.New("missing required argument 'label'")
}
plabel, popts := parseGetByBaseOptions(vu.Context(), label, true, opts)
ml := mapLocator(vu, p.GetByLabel(plabel, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByPlaceholder": func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(placeholder) {
return nil, errors.New("missing required argument 'placeholder'")
}
pplaceholder, popts := parseGetByBaseOptions(vu.Context(), placeholder, false, opts)
ml := mapLocator(vu, p.GetByPlaceholder(pplaceholder, 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'")View on GitHub (pinned to 93accf6570)
Solutions
- Pass a string or RegExp: page.getByLabel('Email') or page.getByLabel(/email/i)
- Guard data-driven labels: page.getByLabel(label ?? 'Email')
- Add a quick assertion on the data source so missing labels fail with your own message
Example fix
// before
page.getByLabel();
// after
page.getByLabel('Email'); Defensive patterns
Strategy: validation
Validate before calling
if (label === undefined || label === null) {
throw new Error(`page.getByLabel: 'label' is required, got ${label}`);
}
const loc = page.getByLabel(label, opts); Type guard
function isTextMatcher(v) {
return typeof v === 'string' || v instanceof RegExp;
} Try / catch
try {
page.getByLabel(label);
} catch (e) {
if (!e.message.includes("missing required argument 'label'")) throw e;
throw new Error(`form label missing from data file`);
} Prevention
- Keep form labels in one constants module with a completeness test so gaps fail early
When it happens
Trigger: page.getByLabel() with no arguments; page.getByLabel(null); label variables that resolve to undefined (missing form definitions in fixtures).
Common situations: Form-testing scripts where the label comes from a data file with gaps; converting page.$('label:has-text(...)') selectors to getByLabel without carrying the text over; optional chaining upstream that silently yields undefined.
Related errors
- missing required argument 'role'
- missing required argument 'altText'
- missing required argument 'placeholder'
- missing required argument 'title'
- missing required argument 'testId'
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/3fcb9799a8ebf82f.
Report an issue: GitHub.