{"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/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/page_mapping.go#L164-L200","documentation":"Thrown by page.getByAltText() in the k6 browser module (internal/js/modules/k6/browser/browser/page_mapping.go:182). The alt argument (string or RegExp matched against image alt attributes) is mandatory; the nullish guard rejects nil/undefined/null before parseGetByBaseOptions builds the selector. The error message uses the name 'altText' even though the JS parameter is just the first positional argument.","triggerScenarios":"Calling page.getByAltText() with no arguments; passing undefined/null explicitly; passing an alt string read from a data fixture row that lacks the alt field.","commonSituations":"Image assertions driven by CMS/A11y exports with missing alt metadata; dynamic image filtering where some test rows have no alt text; scripts migrated from Playwright where the argument was dropped.","solutions":["Pass a string or RegExp: page.getByAltText('Company logo')","Default the value: const alt = img.alt ?? 'Company logo'","Skip the filter when optional: if (alt) loc = page.getByAltText(alt)","Validate fixture rows up front so missing alt fields fail before browser work starts"],"exampleFix":"// before\nconst logo = page.getByAltText(imgMeta.alt); // imgMeta.alt missing for one image\n\n// after\nconst logo = page.getByAltText(imgMeta.alt ?? 'Company logo');","handlingStrategy":"validation","validationCode":"const alt = imgMeta.alt ?? 'Company logo';\nif (alt === undefined || alt === null) throw new Error('altText is required');\nconst loc = page.getByAltText(alt);","typeGuard":"function isNonEmptyStringOrRegExp(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}\n// usage: if (!isNonEmptyStringOrRegExp(alt)) throw new Error('altText must be a non-empty string or RegExp');","tryCatchPattern":"try {\n  const loc = page.getByAltText(alt);\n} catch (e) {\n  if (/missing required argument 'altText'/.test(e.message)) throw new Error(`alt text missing for image ${imgMeta.src}`);\n  throw e;\n}","preventionTips":["Validate accessibility metadata (alt fields) in the data source before the run","Default alt values with ?? in data-driven image checks","Skip the filter when an image legitimately has no alt text","Keep editor typings active to catch zero-argument calls"],"tags":["browser","page","accessibility","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"}