{"record":{"id":"e3506de057a8e440","repo":"grafana/k6","slug":"missing-required-argument-alttext-e3506d","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/locator_mapping.go","lineNumber":236,"sourceCode":"\t\t\"getAttribute\": func(name string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tcopts := common.NewFrameBaseOptions(lo.Timeout())\n\t\t\tif err := copts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing get attribute options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\ts, ok, err := lo.GetAttribute(name, copts)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err //nolint:wrapcheck\n\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'\")","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/locator_mapping.go#L218-L254","documentation":"Locator.getByAltText(altText) in the k6 browser module (chained on an existing Locator) requires a non-nullish first argument; the mapping in locator_mapping.go throws before any CDP activity. 'Nullish' includes missing, null, and undefined arguments. The alt text (string or RegExp) is the sole input used to narrow the locator to img/area descendants, matching Playwright's contract.","triggerScenarios":"Calling page.locator('div').getByAltText() with no argument, passing null/undefined, or forwarding an undefined alt variable while chaining locators in a page object.","commonSituations":"Page-object chaining where the alt constant is missing from the selectors module, data-driven component tests with sparse fields, incomplete Playwright port.","solutions":["Pass a string or RegExp: locator.getByAltText('badge-icon')","Validate/default the alt value before chaining; assert it is defined in the page-object constructor","Fix renamed or unexported selector constants","Use a RegExp for variable alt text, e.g. getByAltText(/^avatar-/)"],"exampleFix":"// before\nconst avatar = page.locator('.user-card').getByAltText(ALT.avatar); // ALT.avatar is undefined\n\n// after\nconst avatar = page.locator('.user-card').getByAltText('user-avatar');","handlingStrategy":"validation","validationCode":"if (!isTextSelector(alt)) throw new Error('alt must be a non-empty string or RegExp before locator.getByAltText');\nlocator.getByAltText(alt);","typeGuard":"function isTextSelector(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  sub = locator.getByAltText(maybeAlt);\n} catch (e) {\n  if (/missing required argument 'altText'/.test(String(e.message))) {\n    throw new Error(`altText missing while building locator under ${selector}`);\n  }\n  throw e;\n}","preventionTips":["In page objects, assert required selector constants are defined in the constructor","Avoid chaining getBy* on values sourced from unvalidated request responses","Keep alt selectors with their parent locator definitions","Write one smoke script per page object; undefined constants fail there first"],"tags":["browser","locator","argument-validation","get-by"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}