grafana/k6 · error

missing required argument 'label'

Error message

missing required argument 'label'

What it means

Thrown by page.getByLabel() in the k6 browser module (internal/js/modules/k6/browser/browser/page_mapping.go:191). The label argument (string or RegExp matched against associated form-label text) is mandatory; the nullish guard fails the call before parseGetByBaseOptions (which also accepts { exact } options as a second argument) can build the selector.

Solutions

  1. Pass a string or RegExp: page.getByLabel('Email address')
  2. Default the value: const label = row.label ?? 'Email address'
  3. Check the data source spelling (labels vs label vs labelText) before the call
  4. Validate required data fields once at script init so failures are early and obvious

Example fix

// before
const email = page.getByLabel(formFields.emailLabel); // formFields.emailLabel undefined

// after
const email = page.getByLabel(formFields.emailLabel ?? 'Email address', { exact: true });
Defensive patterns

Strategy: validation

Validate before calling

const label = formFields.emailLabel ?? 'Email address';
if (label === undefined || label === null) throw new Error('label is required');
const loc = page.getByLabel(label);

Type guard

function isNonEmptyStringOrRegExp(v) {
  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;
}
// usage: if (!isNonEmptyStringOrRegExp(label)) throw new Error('label must be a non-empty string or RegExp');

Try / catch

try {
  const loc = page.getByLabel(label);
} catch (e) {
  if (/missing required argument 'label'/.test(e.message)) throw new Error(`label missing for field ${field.name}`);
  throw e;
}

Prevention

When it happens

Trigger: Calling page.getByLabel() with zero arguments; passing null/undefined explicitly; passing a label from a data object where the key is absent or the accessor returns undefined.

Common situations: Form-filling scripts parameterized from CSV/JSON where some rows omit the label column; i18n label bundles with missing keys; label constants object refactored and one lookup silently became undefined.

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


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/3fcb9799a8ebf82f. Report an issue: GitHub.

Appendix: 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 8d06114777)