{"record":{"id":"aae94d3b4965de84","repo":"grafana/k6","slug":"parsing-select-option-values-w","errorCode":null,"errorMessage":"parsing select option values: %w","messagePattern":"parsing select option values: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/locator_mapping.go","lineNumber":362,"sourceCode":"\t\t\t}), nil\n\t\t},\n\t\t\"inputValue\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tcopts := common.NewFrameInputValueOptions(lo.Timeout())\n\t\t\tif err := copts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing input value options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn lo.InputValue(copts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"selectOption\": func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tcopts := common.NewFrameSelectOptionOptions(lo.Timeout())\n\t\t\tif err := copts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing select option options: %w\", err)\n\t\t\t}\n\t\t\tconvValues, err := ConvertSelectOptionValues(vu.Runtime(), values)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing select option values: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn lo.SelectOption(convValues, copts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"press\": func(key string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tcopts := common.NewFramePressOptions(lo.Timeout())\n\t\t\tif err := copts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing press options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, lo.Press(key, copts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\n\t\t\"pressSequentially\": func(text string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tcopts := common.NewFrameTypeOptions(lo.Timeout())\n\t\t\tif err := copts.Parse(vu.Context(), opts); err != nil {","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/locator_mapping.go#L344-L380","documentation":"Thrown when the values argument of locator.selectOption(values, opts) cannot be converted by ConvertSelectOptionValues. Accepted shapes: null/undefined (select nothing... actually returns no options), a plain string (matches value or label), an array of strings and/or descriptor objects {value?: string, label?: string, index?: number}, a single descriptor object, an ElementHandle pointing at an <option>, or a sobek object with value/label/index getters. Any other type or malformed descriptor produces 'parsing select option values: %w' wrapping a specific cause (see errors 495-499).","triggerScenarios":"selectOption(42) or selectOption(true) — unsupported scalar kind; selectOption([1, 2]) — array items that are neither string nor object; selectOption({ value: 2 }) — descriptor value/label not a string; selectOption(['a', null]) — null item in array.","commonSituations":"Passing numbers (option indices) directly instead of { index: n } descriptors; data-driven scripts feeding unvalidated API/JSON data into selectOption; assuming Playwright's SelectOption class objects work in k6.","solutions":["Wrap numeric selection in a descriptor: selectOption({ index: 2 }) instead of selectOption(2)","Ensure every array item is a string or an object with only string value/label and numeric index","Sanitize external data before passing it: map values to strings or descriptors","Pass an ElementHandle only when it references an actual <option> element"],"exampleFix":"// before\nawait page.locator('select').selectOption([0, 2]);\n\n// after\nawait page.locator('select').selectOption([{ index: 0 }, { index: 2 }]);","handlingStrategy":"type-guard","validationCode":"function normalizeSelectValues(values) {\n  if (values === null || values === undefined) return values;\n  if (typeof values === 'string') return values;\n  if (Array.isArray(values)) {\n    return values\n      .filter((v) => v !== null && v !== undefined)\n      .map((v) => {\n        if (typeof v === 'string') return v;\n        if (typeof v === 'number') return { index: v };\n        if (typeof v === 'object') {\n          const o = {};\n          if ('value' in v) o.value = String(v.value);\n          if ('label' in v && v.label !== null) o.label = String(v.label);\n          if ('index' in v) o.index = Number(v.index);\n          return o;\n        }\n        throw new TypeError(`Unsupported selectOption item: ${typeof v}`);\n      });\n  }\n  if (typeof values === 'object') return { value: String(values.value ?? ''), label: values.label !== undefined ? String(values.label) : undefined };\n  throw new TypeError(`Unsupported selectOption values type: ${typeof values}`);\n}","typeGuard":"function isSelectOptionValues(v) {\n  if (v === null || v === undefined || typeof v === 'string') return true;\n  if (Array.isArray(v)) return v.every((item) =>\n    typeof item === 'string' ||\n    (typeof item === 'object' && item !== null &&\n      (item.value === undefined || typeof item.value === 'string') &&\n      (item.label === undefined || typeof item.label === 'string') &&\n      (item.index === undefined || typeof item.index === 'number')));\n  if (typeof v === 'object') {\n    return (v.value === undefined || typeof v.value === 'string') &&\n           (v.label === undefined || typeof v.label === 'string') &&\n           (v.index === undefined || typeof v.index === 'number');\n  }\n  return false;\n}","tryCatchPattern":"try {\n  await locator.selectOption(values, opts);\n} catch (e) {\n  if (/parsing select option values/.test(String(e.message))) {\n    throw new Error(`Invalid selectOption values: ${JSON.stringify(values)} (${e.message})`);\n  }\n  throw e;\n}","preventionTips":["Never pass raw numbers as values; wrap them as { index: n }","Filter null/undefined out of data-driven arrays before calling selectOption","Stringify value/label fields coming from JSON payloads"],"tags":["k6","browser","locator","selectoption","type-validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}