{"record":{"id":"7063050901ff3795","repo":"grafana/k6","slug":"missing-required-argument-placeholder-706305","errorCode":null,"errorMessage":"missing required argument 'placeholder'","messagePattern":"missing required argument 'placeholder'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/locator_mapping.go","lineNumber":255,"sourceCode":"\t\t\t\treturn nil, errors.New(\"missing required argument 'altText'\")\n\t\t\t}\n\t\t\tpalt, popts := parseGetByBaseOptions(vu.Context(), alt, false, opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByAltText(palt, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByLabel\": func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(label) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'label'\")\n\t\t\t}\n\t\t\tplabel, popts := parseGetByBaseOptions(vu.Context(), label, true, opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByLabel(plabel, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByPlaceholder\": func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(placeholder) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'placeholder'\")\n\t\t\t}\n\t\t\tpplaceholder, popts := parseGetByBaseOptions(vu.Context(), placeholder, false, opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByPlaceholder(pplaceholder, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByRole\": func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(role) {\n\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'\")","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/locator_mapping.go#L237-L273","documentation":"Thrown by the chained locator filter locator.getByPlaceholder() in the k6 browser module (internal/js/modules/k6/browser/browser/locator_mapping.go:254). The first argument (a string or RegExp matched against an input's placeholder attribute) is mandatory; k6 checks it with k6common.IsNullish (nil/undefined/null, js/common/util.go:65) and fails fast because it cannot build the CDP selector without it. Note that an empty string is NOT rejected here — it silently produces a locator that matches nothing.","triggerScenarios":"Calling page.locator('form').getByPlaceholder() with zero arguments; passing an explicit null or undefined; passing a variable that was never assigned, e.g. row.placeholder when the data row lacks that field or the index is out of range.","commonSituations":"Placeholders driven by env vars, CSV/JSON test data, or shared config objects with missing keys; refactors that renamed the variable holding the value; scripts ported from Playwright where the argument got dropped during translation.","solutions":["Pass a string or RegExp as the first argument: form.getByPlaceholder('Username')","If the value is dynamic, default it before the call: const ph = row.placeholder ?? 'Username'","Log/validate the variable right before the call to find where it becomes undefined","If empty strings should also be rejected, assert typeof v === 'string' && v.trim() !== '' yourself — k6 only rejects null/undefined here"],"exampleFix":"// before\nconst row = data[i];\nconst loc = form.getByPlaceholder(row.missingField);\n\n// after\nconst row = data[i];\nconst loc = form.getByPlaceholder(row.missingField ?? 'Username');","handlingStrategy":"validation","validationCode":"const ph = row.placeholder ?? 'Username';\nif (ph === undefined || ph === null) throw new Error('placeholder is required');\nconst loc = form.getByPlaceholder(ph);","typeGuard":"function isNonEmptyStringOrRegExp(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}\n// usage: if (!isNonEmptyStringOrRegExp(ph)) throw new Error('placeholder must be a non-empty string or RegExp');","tryCatchPattern":"try {\n  const loc = form.getByPlaceholder(ph);\n} catch (e) {\n  if (/missing required argument 'placeholder'/.test(e.message)) throw new Error(`placeholder missing for data row ${i}`);\n  throw e;\n}","preventionTips":["Always pass a literal string or RegExp as the first argument to getBy* methods","Default dynamic values with ?? before passing them","Validate data fixtures in init context so missing fields fail before browser work starts","Use the k6 browser TypeScript typings in your editor so omitted arguments are flagged while writing"],"tags":["browser","locator","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"}