{"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":363,"sourceCode":"\t\t\t}), nil\n\t\t},\n\t\t\"inputValue\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tcopts, err := parseFrameInputValueOptions(rt, opts, lo.Timeout())\n\t\t\tif 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, err := parseFrameSelectOptionOptions(rt, opts, lo.Timeout())\n\t\t\tif 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, err := parseFramePressOptions(rt, opts, lo.Timeout())\n\t\t\tif 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, err := parseFrameTypeOptions(rt, opts, lo.Timeout())\n\t\t\tif err != nil {","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/locator_mapping.go#L345-L381","documentation":"Thrown synchronously when the values (first) argument to locator.selectOption(values, opts) cannot be converted. The mapping (locator_mapping.go:362-364) calls ConvertSelectOptionValues (browser/mapping.go:50-129) and wraps failures as \"parsing select option values: %w\". Supported shapes are: a string, an object with value/label/index keys, an array mixing both, or an ElementHandle; anything else yields errors like \"options: expected string or object, got float64\" or \"options: unsupported type ...\". This is the most value-sensitive error in the locator mapping — numeric array entries are the classic trigger.","triggerScenarios":"locator.selectOption([1, 2]) (numbers instead of strings or {value:...} objects); locator.selectOption(true) or a bare number; an array containing null/booleans; an object whose value/label are not strings (index must be an integer).","commonSituations":"Selecting options by numeric value attribute read from APIs as JSON numbers: selectOption(data.ids) where ids is number[]; passing a Set or Map instead of an array; porting Playwright tests where a mixed array silently worked because keys were strings.","solutions":["Map numeric arrays to strings or option objects: values.map(String) or values.map(v => ({ value: String(v) }))","Use the documented shapes: 'blue', { value: 'blue' }, { label: 'Blue' }, { index: 2 }, or arrays thereof","Convert Set/Map to Array.from(...) before passing","Validate the array contents before the call when data comes from an API response"],"exampleFix":"// before\nconst ids = resp.json().categoryIds; // number[]\nawait locator.selectOption(ids); // \"parsing select option values: options: expected string or object, got float64\"\n\n// after\nconst ids = resp.json().categoryIds.map(String);\nawait locator.selectOption(ids);","handlingStrategy":"validation","validationCode":"function toSelectValues(values) {\n  const arr = Array.isArray(values) ? values : [values];\n  return arr.map(v => {\n    if (typeof v === 'string') return v;\n    if (typeof v === 'number' && Number.isInteger(v)) return { index: v };\n    if (v instanceof Object && !Array.isArray(v)) {\n      if (typeof v.value === 'string' || v.value == null) return v;\n      if (v.value !== undefined) return { ...v, value: String(v.value) };\n      return v;\n    }\n    throw new TypeError(`selectOption cannot take ${typeof v}`);\n  });\n}\nawait locator.selectOption(toSelectValues(apiIds), { timeout: 5000 });","typeGuard":"function isSelectValue(v) {\n  if (typeof v === 'string') return true;\n  if (v && typeof v === 'object' && !Array.isArray(v)) {\n    const { value, label, index } = v;\n    return (value === undefined || typeof value === 'string') &&\n      (label === undefined || typeof label === 'string') &&\n      (index === undefined || Number.isInteger(index));\n  }\n  return false;\n}","tryCatchPattern":"try {\n  await locator.selectOption(values);\n} catch (e) {\n  if (String(e).includes('parsing select option values'))\n    throw new Error(`selectOption values must be strings or {value|label|index} objects, got: ${JSON.stringify(values)}`);\n  throw e;\n}","preventionTips":["Map numeric API ids to strings before selectOption","Only pass string, {value}, {label}, {index}, arrays thereof, or an ElementHandle","Validate external data shapes before driving the select element","Convert Set/Map inputs with Array.from first"],"tags":["k6","browser","locator","selectoption","values","type-conversion"],"backgroundTag":"invalid-options-object","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"}