grafana/k6 · error

missing required argument 'label'

Error message

missing required argument 'label'

What it means

Frame.getByLabel(label) on a k6 browser Frame requires a non-nullish first argument; the mapping in frame_mapping.go rejects it before contacting the browser. The label text (string or RegExp) is the only way this locator resolves form controls via their label association. Playwright's getByLabel carries the same requirement.

Source

Thrown at internal/js/modules/k6/browser/browser/frame_mapping.go:149

				}
				if !ok {
					return nil, nil //nolint:nilnil
				}
				return s, nil
			}), 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, f.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, f.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, f.GetByPlaceholder(pplaceholder, popts))
			return rt.ToValue(ml).ToObject(rt), nil
		},
		"getByRole": func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) {
			if k6common.IsNullish(role) {
				return nil, errors.New("missing required argument 'role'")

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass the label string or RegExp: frame.getByLabel('Password')
  2. Default or validate the label value before the call (const label = field.label ?? field.ariaLabel)
  3. Fix the undefined property or import
  4. Use a RegExp for labels with required-field markers, e.g. getByLabel(/^Email/)

Example fix

// before
const pw = page.frame('#login').getByLabel(labelFor); // labelFor is undefined

// after
const labelFor = 'Password';
const pw = page.frame('#login').getByLabel(labelFor);
Defensive patterns

Strategy: validation

Validate before calling

const label = field.label ?? field.name;
if (!isTextSelector(label)) throw new Error(`label required for ${field.id}`);
frame.getByLabel(label);

Type guard

function isTextSelector(v) {
  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;
}

Try / catch

try {
  loc = frame.getByLabel(maybeLabel);
} catch (e) {
  if (/missing required argument 'label'/.test(String(e.message))) {
    throw new Error(`label missing for field ${field.id} in frame`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling frame.getByLabel() with no argument, passing null/undefined, or passing a field-label variable that is undefined because the fixture lacks that key.

Common situations: Form-filling helpers driven by field-definition arrays with optional labels, i18n label lookups that miss, or renamed variables during refactors.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/7378a34220264818. Report an issue: GitHub.