grafana/k6 · error

missing required argument 'placeholder'

Error message

missing required argument 'placeholder'

What it means

Thrown by the Page mapping's getByPlaceholder method. The placeholder text is mandatory; the mapping rejects nullish values with k6common.IsNullish before parsing string/RegExp and options. This is the standard fail-fast guard for the getBy* locator family.

Source

Thrown at internal/js/modules/k6/browser/browser/page_mapping.go:200

				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'")
			}
			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'")

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass a string or RegExp: page.getByPlaceholder('Search...') or page.getByPlaceholder(/search/i)
  2. Default-guard dynamic values: page.getByPlaceholder(ph ?? 'Search...')
  3. Prefer locators over raw element queries so a single missing argument is caught at the call site

Example fix

// before
page.getByPlaceholder();

// after
page.getByPlaceholder('Search...');
Defensive patterns

Strategy: validation

Validate before calling

if (placeholder === undefined || placeholder === null) {
  throw new Error(`page.getByPlaceholder: 'placeholder' is required, got ${placeholder}`);
}
const loc = page.getByPlaceholder(placeholder, opts);

Type guard

function isTextMatcher(v) {
  return typeof v === 'string' || v instanceof RegExp;
}

Try / catch

try {
  page.getByPlaceholder(ph);
} catch (e) {
  if (!e.message.includes("missing required argument 'placeholder'")) throw e;
  throw new Error(`placeholder value missing`);
}

Prevention

When it happens

Trigger: page.getByPlaceholder() with no arguments; page.getByPlaceholder(undefined) from unset input data; passing options first: page.getByPlaceholder({ exact: true }).

Common situations: Login/search flows where the placeholder is sourced from localization files that may be incomplete; selector migrations from [placeholder="Search"] to getByPlaceholder; typos in variable names leaving the argument undefined.

Related errors


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