{"record":{"id":"73d59bfcabc52054","repo":"grafana/k6","slug":"missing-required-argument-text","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/frame_locator_mapping.go","lineNumber":62,"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, fl.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, fl.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, fl.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, fl.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, fl.Locator(selector, parseLocatorOptions(rt, opts)))\n\t\t},","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/frame_locator_mapping.go#L44-L80","documentation":"FrameLocator.getByText(text) in the k6 browser module requires a non-nullish first argument; the mapping layer throws before any browser communication. The text (string or RegExp) is the locator's only search criterion for finding elements by their text content, with options only refining matching behavior. Playwright's getByText has the same mandatory argument.","triggerScenarios":"Calling page.frameLocator('iframe').getByText(), passing null/undefined explicitly, or passing a text variable that is undefined because the content fixture or i18n lookup returned nothing.","commonSituations":"Assertion helpers that receive an optional message parameter, localized-content tests with missing translation keys, or template literals that evaluate to undefined.","solutions":["Pass the text string or RegExp: frameLocator.getByText('Welcome back')","Default or validate content/i18n-sourced values before the call (const text = i18n.welcome ?? 'Welcome')","Fix the undefined variable or missing translation key","For fuzzy matches use a RegExp, e.g. getByText(/welcome/i), instead of omitting the argument"],"exampleFix":"// before\nconst msg = page.frameLocator('#frame').getByText(welcomeKey); // welcomeKey is undefined\n\n// after\nconst welcomeKey = 'Welcome back';\nconst msg = page.frameLocator('#frame').getByText(welcomeKey);","handlingStrategy":"validation","validationCode":"const text = expected.welcome;\nif (!isTextSelector(text)) throw new Error('expected.welcome is required for getByText');\nframeLocator.getByText(text);","typeGuard":"function isTextSelector(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  loc = frameLocator.getByText(maybeText);\n} catch (e) {\n  if (/missing required argument 'text'/.test(String(e.message))) {\n    throw new Error(`expected text missing; fixture key='${key}'`);\n  }\n  throw e;\n}","preventionTips":["Validate assertion fixtures at script start rather than mid-iteration","Prefer ?? defaults on i18n/content lookups so text is never undefined at the call site","Lint getBy* call sites for empty argument lists","Log the resolved text once per scenario to make data gaps obvious in output"],"tags":["browser","frame-locator","argument-validation","get-by","text-matching"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}