{"record":{"id":"474759fd5b0511cc","repo":"grafana/k6","slug":"missing-required-argument-label","errorCode":null,"errorMessage":"missing required argument 'label'","messagePattern":"missing required argument 'label'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/frame_locator_mapping.go","lineNumber":26,"sourceCode":"\tk6common \"go.k6.io/k6/v2/js/common\"\n)\n\n// mapFrameLocator API to the JS module.\nfunc mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping {\n\trt := vu.Runtime()\n\treturn mapping{\n\t\t\"getByAltText\": func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(alt) {\n\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, fl.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, fl.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, fl.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'\")","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/frame_locator_mapping.go#L8-L44","documentation":"FrameLocator.getByLabel(label) in the k6 browser module requires a non-nullish first argument; the mapping layer in frame_locator_mapping.go throws before contacting the browser. The label text (string or RegExp) identifies form controls by their associated label element, and without it the locator has no search criterion. This mirrors Playwright, where the label argument is mandatory.","triggerScenarios":"Calling page.frameLocator('iframe').getByLabel() with no argument, passing null/undefined, or passing a form-field name variable that is undefined because the test-data object lacks that key.","commonSituations":"Scripts iterating over form definitions where some entries have no label, renaming label variables during refactors, or optional-chained data access (form?.label) that silently yields undefined.","solutions":["Pass the label string or RegExp: frameLocator.getByLabel('Email address')","Default or validate the data-sourced value before the call (const label = field.label ?? field.fallback)","Correct the typo/missing property that produces undefined","For labels with dynamic parts, use a RegExp such as getByLabel(/Email/)"],"exampleFix":"// before\nconst email = page.frameLocator('#form-frame').getByLabel(fieldName); // fieldName is undefined\n\n// after\nconst fieldName = 'Email';\nconst email = page.frameLocator('#form-frame').getByLabel(fieldName);","handlingStrategy":"validation","validationCode":"const label = field.label;\nif (!isTextSelector(label)) throw new Error(`field.label is required for getByLabel: ${field.id}`);\nframeLocator.getByLabel(label);","typeGuard":"function isTextSelector(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  loc = frameLocator.getByLabel(maybeLabel);\n} catch (e) {\n  if (/missing required argument 'label'/.test(String(e.message))) {\n    throw new Error(`label missing for ${field.id}; check the form definition`);\n  }\n  throw e;\n}","preventionTips":["Model form fields as objects with a required label property and validate the schema once at startup","Prefer getByLabel(label ?? field.name) patterns only when a real fallback exists","Lint for getBy*() call sites with zero arguments","Log field definitions once when a form helper starts so gaps are visible in output"],"tags":["browser","frame-locator","argument-validation","get-by","forms"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}