{"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":282,"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":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/locator_mapping.go#L264-L300","documentation":"Thrown by locator.getByText() in the k6 browser module (internal/js/modules/k6/browser/browser/locator_mapping.go:281). The text argument (string or RegExp matched against element text content) is mandatory; the nullish guard fails the call before parseGetByBaseOptions builds the selector, since there is no way to query 'text of nothing'.","triggerScenarios":"Calling parent.getByText() with zero arguments; passing undefined/null explicitly; passing a text variable computed from a function that returned undefined (e.g. missing .textContent).","commonSituations":"Labels/assertion strings read from i18n bundles or data files with missing keys; text extracted from a previous DOM node that did not exist; scripts parameterized so that some rows have no text filter.","solutions":["Pass a string or RegExp: page.locator('ul').getByText('Item 1')","Default dynamic values: const label = row.label ?? 'Item 1'","If the text is genuinely optional, branch instead of calling: if (label) child = parent.getByText(label)","Trace where the variable becomes undefined (console.log or k6 console.debug) and fix the producer"],"exampleFix":"// before\nconst item = page.locator('ul').getByText(getLabel(i)); // getLabel returns undefined for some i\n\n// after\nconst item = page.locator('ul').getByText(getLabel(i) ?? `Item ${i}`);","handlingStrategy":"validation","validationCode":"const label = getLabel(i) ?? `Item ${i}`;\nif (label === undefined || label === null) throw new Error('text is required');\nconst loc = parent.getByText(label);","typeGuard":"function isNonEmptyStringOrRegExp(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}\n// usage: if (!isNonEmptyStringOrRegExp(label)) throw new Error('text must be a non-empty string or RegExp');","tryCatchPattern":"try {\n  const loc = parent.getByText(label);\n} catch (e) {\n  if (/missing required argument 'text'/.test(e.message)) throw new Error(`text missing for row ${i}`);\n  throw e;\n}","preventionTips":["Check the producer of the text value (textContent, i18n lookup) before the call","Branch when the text filter is optional instead of passing undefined","Default dynamic labels with ??","Assert fixture text fields exist once at script init"],"tags":["browser","locator","text-matching","argument-validation","api-misuse"],"backgroundTag":"missing-required-argument","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}