grafana/k6 · error

missing required argument 'title'

Error message

missing required argument 'title'

What it means

Thrown by the Frame mapping's getByTitle method in k6's browser module. The title argument is mandatory; the Go mapping checks it with k6common.IsNullish before calling lo.GetByTitle. Passing null/undefined (or omitting the argument) produces this error instead of a confusing low-level failure later.

Source

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

				return nil, errors.New("missing required argument 'testId'")
			}
			ptestID := parseStringOrRegex(testID, false)

			ml := mapLocator(vu, lo.GetByTestID(ptestID))
			return rt.ToValue(ml).ToObject(rt), nil
		},
		"getByText": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) {
			if k6common.IsNullish(text) {
				return nil, errors.New("missing required argument 'text'")
			}
			ptext, popts := parseGetByBaseOptions(vu.Context(), text, true, opts)

			ml := mapLocator(vu, lo.GetByText(ptext, 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, lo.GetByTitle(ptitle, popts))
			return rt.ToValue(ml).ToObject(rt), nil
		},
		"locator": func(selector string, opts sobek.Value) mapping {
			return mapLocator(vu, lo.Locator(selector, parseLocatorOptions(rt, opts)))
		},
		"frameLocator": func(selector string) *sobek.Object {
			mfl := mapFrameLocator(vu, lo.FrameLocator(selector))
			return rt.ToValue(mfl).ToObject(rt)
		},
		"innerHTML": func(opts sobek.Value) (*sobek.Promise, error) {
			copts := common.NewFrameInnerHTMLOptions(lo.Timeout())
			if err := copts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing inner HTML options: %w", err)
			}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass a string or RegExp title: frame.getByTitle('Close') or frame.getByTitle(/close/i)
  2. Default-guard data-driven values: frame.getByTitle(title ?? 'Close')
  3. Linter rule or code review for getBy* calls with zero arguments

Example fix

// before
frame.getByTitle();

// after
frame.getByTitle('Close');
Defensive patterns

Strategy: validation

Validate before calling

if (title === undefined || title === null) {
  throw new Error(`frame.getByTitle: 'title' is required, got ${title}`);
}
const loc = frame.getByTitle(title);

Type guard

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

Try / catch

try {
  frame.getByTitle(title);
} catch (e) {
  if (!e.message.includes("missing required argument 'title'")) throw e;
  throw new Error(`missing title in fixture/data`);
}

Prevention

When it happens

Trigger: frame.getByTitle() with no arguments; frame.getByTitle(null); passing a variable that is undefined because a lookup (e.g. data.title) returned nothing.

Common situations: Dynamic titles sourced from config/data that can be missing; renaming calls from locator('[title="..."]') to getByTitle and dropping the argument; partial application or callback wiring that passes undefined.

Related errors


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