{"record":{"id":"9efa85277a1977ac","repo":"grafana/k6","slug":"missing-required-argument-alttext-9efa85","errorCode":null,"errorMessage":"missing required argument 'altText'","messagePattern":"missing required argument 'altText'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/page_mapping.go","lineNumber":182,"sourceCode":"\t\t\t\t}\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, nil //nolint:nilnil\n\t\t\t\t}\n\t\t\t\treturn s, nil\n\t\t\t}), 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, p.GetByRole(role.String(), popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), 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, p.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, p.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'\")","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/page_mapping.go#L164-L200","documentation":"Thrown by the Page mapping's getByAltText method. The alt text to match is a mandatory first argument; the Go mapping validates it with k6common.IsNullish and then parses it via parseGetByBaseOptions (string or RegExp). Omitting it or passing null/undefined fails fast here.","triggerScenarios":"page.getByAltText() with no arguments; page.getByAltText(undefined) from an unset variable; passing only an options object as the first argument.","commonSituations":"Looking up images whose alt text comes from test data that can be empty; migrating selectors from [alt=\"logo\"] to getByAltText and dropping the value; refactors that leave the argument unbound.","solutions":["Pass a string or RegExp: page.getByAltText('k6 logo') or page.getByAltText(/logo/i)","Default or validate data-driven alt text before the call: page.getByAltText(alt ?? 'logo')","Fail early with your own descriptive error if the alt text is a required test input"],"exampleFix":"// before\npage.getByAltText();\n\n// after\npage.getByAltText('k6 logo');","handlingStrategy":"validation","validationCode":"if (alt === undefined || alt === null) {\n  throw new Error(`page.getByAltText: 'altText' is required, got ${alt}`);\n}\nconst loc = page.getByAltText(alt, opts);","typeGuard":"function isTextMatcher(v) {\n  return typeof v === 'string' || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  page.getByAltText(alt);\n} catch (e) {\n  if (!e.message.includes(\"missing required argument 'altText'\")) throw e;\n  throw new Error(`image alt text missing from test data`);\n}","preventionTips":["When scraping alt texts from a page or fixture, filter out nullish entries up front"],"tags":["browser","page","getbyalttext","locator","argument-validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}