{"record":{"id":"0be0b374a76c656a","repo":"grafana/k6","slug":"missing-required-argument-role","errorCode":null,"errorMessage":"missing required argument 'role'","messagePattern":"missing required argument 'role'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/frame_locator_mapping.go","lineNumber":44,"sourceCode":"\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'\")\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'\")","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/frame_locator_mapping.go#L26-L62","documentation":"FrameLocator.getByRole(role, options) in the k6 browser module requires a non-nullish first argument naming an ARIA role; the mapping layer throws this error before parsing options or touching CDP. The role string (e.g. 'button', 'link', 'textbox') is the primary locator input — options like name or exact are secondary and cannot substitute for it. This matches Playwright, where the role argument is mandatory.","triggerScenarios":"Calling page.frameLocator('iframe').getByRole() with no role, passing null/undefined, or passing a role variable that resolves to undefined while intending to supply it via options ({ name: 'Submit' }) instead.","commonSituations":"Confusion between the role argument and the options.name parameter, data-driven role matrices with missing entries, or helper functions with an optional role parameter forwarded directly.","solutions":["Pass an ARIA role string as the first argument: frameLocator.getByRole('button', { name: 'Submit' })","If the accessible name was meant as the criterion, keep role and pass name in options rather than dropping the role","Validate/default role variables from test data before the call","Check for typos in the variable or property name supplying the role"],"exampleFix":"// before\nconst btn = page.frameLocator('#frame').getByRole(undefined, { name: 'Submit' });\n\n// after\nconst btn = page.frameLocator('#frame').getByRole('button', { name: 'Submit' });","handlingStrategy":"validation","validationCode":"const role = roles.submit; // 'button'\nif (typeof role !== 'string' || role.length === 0) throw new Error('ARIA role is required for getByRole');\nframeLocator.getByRole(role, opts);","typeGuard":"const ARIA_ROLES = new Set(['button','link','textbox','checkbox','radio','heading','img','list','listitem','navigation','main','banner','contentinfo','form','table','row','cell','dialog','alert','search','tab','tablist','option','combobox','menuitem','progressbar','slider','switch']);\nfunction isAriaRole(v) {\n  return typeof v === 'string' && ARIA_ROLES.has(v);\n}","tryCatchPattern":"try {\n  loc = frameLocator.getByRole(maybeRole, opts);\n} catch (e) {\n  if (/missing required argument 'role'/.test(String(e.message))) {\n    throw new Error('getByRole needs the role first; put accessible names in { name } options');\n  }\n  throw e;\n}","preventionTips":["Remember the argument order: role string first, refinement options second","Validate role tables from test data against a known ARIA role set at startup","Write page-object helpers that require the role parameter (no default undefined)","Review ported Playwright code for getByRole calls that lost their first argument"],"tags":["browser","frame-locator","argument-validation","get-by","aria"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}