{"record":{"id":"b59456b303b9e34e","repo":"grafana/k6","slug":"missing-required-argument-text-b59456","errorCode":null,"errorMessage":"missing required argument 'text'","messagePattern":"missing required argument 'text'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/locator_mapping.go","lineNumber":281,"sourceCode":"\t\t\t\treturn nil, errors.New(\"missing required argument 'role'\")\n\t\t\t}\n\t\t\tpopts := parseGetByRoleOptions(vu.Context(), opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByRole(role.String(), popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByTestId\": func(testID sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(testID) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'testId'\")\n\t\t\t}\n\t\t\tptestID := parseStringOrRegex(testID, false)\n\n\t\t\tml := mapLocator(vu, lo.GetByTestID(ptestID))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByText\": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(text) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'text'\")\n\t\t\t}\n\t\t\tptext, popts := parseGetByBaseOptions(vu.Context(), text, true, opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByText(ptext, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByTitle\": func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(title) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'title'\")\n\t\t\t}\n\t\t\tptitle, popts := parseGetByBaseOptions(vu.Context(), title, false, opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByTitle(ptitle, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"locator\": func(selector string, opts sobek.Value) mapping {\n\t\t\treturn mapLocator(vu, lo.Locator(selector, parseLocatorOptions(rt, opts)))\n\t\t},","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/locator_mapping.go#L263-L299","documentation":"Thrown by the Frame mapping's getByText method in k6's browser module. The first argument (the text to match) is mandatory and is validated on the Go side with k6common.IsNullish before a locator is built, mirroring Playwright's API contract. Any nullish JS value (undefined, null) passed as `text` triggers this error.","triggerScenarios":"Calling frame.getByText() with no arguments, or passing undefined/null explicitly: frame.getByText(undefined), or a variable that was never assigned (const text; frame.getByText(text)).","commonSituations":"Test data drives the text (CSV, env var) and the value is empty/unset; refactoring from page.$('text=Submit') to getByText and forgetting the argument; copy-pasting Playwright snippets that assumed an optional first parameter.","solutions":["Pass a string or RegExp as the first argument: frame.getByText('Submit') or frame.getByText(/submit/i)","If the value comes from data, default or guard it first: frame.getByText(text ?? 'Submit'), or throw a descriptive error when it is missing","Audit the call site for variables that can be undefined (destructuring, optional JSON fields) before they reach getByText"],"exampleFix":"// before\nconst text;\nframe.getByText(text);\n\n// after\nframe.getByText(text ?? 'Submit')","handlingStrategy":"validation","validationCode":"if (text === undefined || text === null) {\n  throw new Error(`frame.getByText: 'text' is required, got ${text}`);\n}\nconst loc = frame.getByText(text);","typeGuard":"function isTextMatcher(v) {\n  return typeof v === 'string' || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  frame.getByText(text);\n} catch (e) {\n  if (!e.message.includes(\"missing required argument 'text'\")) throw e;\n  throw new Error(`test data missing text value: ${text}`); // rethrow with context\n}","preventionTips":["Type-check test data at load time so nullish values never reach getBy* calls","Wrap getBy* calls in small helper functions that validate the first argument","Add a lint rule or code-review checklist item for getBy* calls with zero arguments"],"tags":["browser","frame","getbytext","locator","argument-validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}