{"record":{"id":"e03f1d3ac8fe859a","repo":"grafana/k6","slug":"missing-required-argument-alttext","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/frame_locator_mapping.go","lineNumber":17,"sourceCode":"package browser\n\nimport (\n\t\"errors\"\n\n\t\"github.com/grafana/sobek\"\n\t\"go.k6.io/k6/v2/internal/js/modules/k6/browser/common\"\n\tk6common \"go.k6.io/k6/v2/js/common\"\n)\n\n// mapFrameLocator API to the JS module.\nfunc mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping {\n\trt := vu.Runtime()\n\treturn mapping{\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, fl.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, 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'\")","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/frame_locator_mapping.go#L1-L35","documentation":"FrameLocator.getByAltText(altText) in the k6 browser module requires a non-nullish first argument; the JS-to-Go mapping layer in frame_locator_mapping.go rejects it before any CDP traffic. 'Nullish' means the argument is absent, null, or undefined (sobek delivers missing arguments as Undefined). The alt text (string or RegExp) is the only way the locator identifies img/area elements, so the call is mandatory, mirroring Playwright's API contract.","triggerScenarios":"Calling page.frameLocator('#iframe').getByAltText() with no argument, passing null or undefined explicitly, or passing a variable that is undefined due to a typo or a missing field in test data (e.g. dataset?.altName).","commonSituations":"Data-driven scripts where some rows lack an alt-text field, ported Playwright tests with a helper that omits the argument, or refactorings that rename the variable being passed.","solutions":["Pass a string or RegExp as the first argument, e.g. frameLocator.getByAltText('company-logo')","If the value comes from test data, default or validate it before the call (const alt = row.alt ?? 'fallback')","Fix the variable name or data field that is resolving to undefined","When matching variable alt attributes, pass a RegExp instead of dropping the argument"],"exampleFix":"// before\nconst logo = page.frameLocator('#ad-frame').getByAltText(altTextVar); // altTextVar is undefined\n\n// after\nconst altTextVar = 'hero-banner';\nconst logo = page.frameLocator('#ad-frame').getByAltText(altTextVar);","handlingStrategy":"validation","validationCode":"const alt = data.alt;\nif (alt === undefined || alt === null) throw new Error('data.alt is required for getByAltText');\nframeLocator.getByAltText(alt);","typeGuard":"function isTextSelector(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  loc = frameLocator.getByAltText(maybeAlt);\n} catch (e) {\n  if (/missing required argument 'altText'/.test(String(e.message))) {\n    throw new Error(`altText missing for frameLocator.getByAltText; source data: ${JSON.stringify(data)}`);\n  }\n  throw e;\n}","preventionTips":["Validate data rows before iteration: skip or fail fast on records missing the alt field","Centralize alt-text selectors as named constants and import them explicitly","Nullish-check optional values with ?? defaults at the data boundary, not at the call site","Smoke-test new page objects once against a live page before adding them to CI"],"tags":["browser","frame-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"}