{"record":{"id":"d81c2da689fa4735","repo":"grafana/k6","slug":"missing-required-argument-label-d81c2d","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/locator_mapping.go","lineNumber":245,"sourceCode":"\t\t\t\t}\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, nil\n\t\t\t\t}\n\t\t\t\treturn s, nil\n\t\t\t}), nil\n\t\t},\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, 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'\")","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/locator_mapping.go#L227-L263","documentation":"Locator.getByLabel(label) in the k6 browser module requires a non-nullish first argument; the mapping layer in locator_mapping.go rejects it before browser communication. The label text (string or RegExp) is the only criterion for resolving labelled form controls beneath the locator's scope. Playwright's API has the same mandatory argument.","triggerScenarios":"Calling page.locator('form').getByLabel() with no argument, passing null/undefined, or forwarding an undefined label from a field-definition object in a page object.","commonSituations":"Form page objects driven by field maps with optional labels, i18n label sources that miss a key, variable renames during refactors.","solutions":["Pass the label string or RegExp: formLocator.getByLabel('Username')","Default or validate the field's label before the call (label ?? field.name)","Fix the missing property/key producing undefined","Use a RegExp for labels with markers, e.g. getByLabel(/^Username/)"],"exampleFix":"// before\nconst user = page.locator('form').getByLabel(fields.user); // fields.user is undefined\n\n// after\nconst user = page.locator('form').getByLabel('Username');","handlingStrategy":"validation","validationCode":"const label = field.label;\nif (!isTextSelector(label)) throw new Error(`field.label required for getByLabel on ${field.id}`);\nlocator.getByLabel(label);","typeGuard":"function isTextSelector(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  sub = locator.getByLabel(maybeLabel);\n} catch (e) {\n  if (/missing required argument 'label'/.test(String(e.message))) {\n    throw new Error(`label missing for field ${field.id}`);\n  }\n  throw e;\n}","preventionTips":["Schema-validate form-field definitions at startup: label is required unless an explicit fallback exists","Make page-object helper signatures require the label argument","Lint for chained getBy*() calls with no arguments","Review refactors that rename label properties for missed call sites"],"tags":["browser","locator","argument-validation","get-by","forms"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}