grafana/k6 · error

missing required argument 'placeholder'

Error message

missing required argument 'placeholder'

What it means

Thrown by the chained locator filter locator.getByPlaceholder() in the k6 browser module (internal/js/modules/k6/browser/browser/locator_mapping.go:254). The first argument (a string or RegExp matched against an input's placeholder attribute) is mandatory; k6 checks it with k6common.IsNullish (nil/undefined/null, js/common/util.go:65) and fails fast because it cannot build the CDP selector without it. Note that an empty string is NOT rejected here — it silently produces a locator that matches nothing.

Solutions

  1. Pass a string or RegExp as the first argument: form.getByPlaceholder('Username')
  2. If the value is dynamic, default it before the call: const ph = row.placeholder ?? 'Username'
  3. Log/validate the variable right before the call to find where it becomes undefined
  4. If empty strings should also be rejected, assert typeof v === 'string' && v.trim() !== '' yourself — k6 only rejects null/undefined here

Example fix

// before
const row = data[i];
const loc = form.getByPlaceholder(row.missingField);

// after
const row = data[i];
const loc = form.getByPlaceholder(row.missingField ?? 'Username');
Defensive patterns

Strategy: validation

Validate before calling

const ph = row.placeholder ?? 'Username';
if (ph === undefined || ph === null) throw new Error('placeholder is required');
const loc = form.getByPlaceholder(ph);

Type guard

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

Try / catch

try {
  const loc = form.getByPlaceholder(ph);
} catch (e) {
  if (/missing required argument 'placeholder'/.test(e.message)) throw new Error(`placeholder missing for data row ${i}`);
  throw e;
}

Prevention

When it happens

Trigger: Calling page.locator('form').getByPlaceholder() with zero arguments; passing an explicit null or undefined; passing a variable that was never assigned, e.g. row.placeholder when the data row lacks that field or the index is out of range.

Common situations: Placeholders driven by env vars, CSV/JSON test data, or shared config objects with missing keys; refactors that renamed the variable holding the value; scripts ported from Playwright where the argument got dropped during translation.

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/7063050901ff3795. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/locator_mapping.go:255

				return nil, errors.New("missing required argument 'altText'")
			}
			palt, popts := parseGetByBaseOptions(vu.Context(), alt, false, opts)

			ml := mapLocator(vu, lo.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, lo.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, lo.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'")
			}
			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'")

View on GitHub (pinned to 8d06114777)