grafana/k6 · error

missing required argument 'altText'

Error message

missing required argument 'altText'

What it means

Thrown by the Page mapping's getByAltText method. The alt text to match is a mandatory first argument; the Go mapping validates it with k6common.IsNullish and then parses it via parseGetByBaseOptions (string or RegExp). Omitting it or passing null/undefined fails fast here.

Source

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

				}
				if !ok {
					return nil, nil //nolint:nilnil
				}
				return s, nil
			}), 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, 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'")

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass a string or RegExp: page.getByAltText('k6 logo') or page.getByAltText(/logo/i)
  2. Default or validate data-driven alt text before the call: page.getByAltText(alt ?? 'logo')
  3. Fail early with your own descriptive error if the alt text is a required test input

Example fix

// before
page.getByAltText();

// after
page.getByAltText('k6 logo');
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

try {
  page.getByAltText(alt);
} catch (e) {
  if (!e.message.includes("missing required argument 'altText'")) throw e;
  throw new Error(`image alt text missing from test data`);
}

Prevention

When it happens

Trigger: page.getByAltText() with no arguments; page.getByAltText(undefined) from an unset variable; passing only an options object as the first argument.

Common situations: Looking up images whose alt text comes from test data that can be empty; migrating selectors from [alt="logo"] to getByAltText and dropping the value; refactors that leave the argument unbound.

Related errors


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