{"record":{"id":"0ac4220db25bd658","repo":"grafana/k6","slug":"options-expected-string-or-object-got-t","errorCode":null,"errorMessage":"options: expected string or object, got %T","messagePattern":"options: expected string or object, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/mapping.go","lineNumber":91,"sourceCode":"\n\t\tfor _, item := range sl {\n\t\t\tswitch item := item.(type) {\n\t\t\tcase string:\n\t\t\t\t// Strings will match values or labels\n\t\t\t\tvalOpt := common.SelectOption{Value: new(string)}\n\t\t\t\t*valOpt.Value = item\n\t\t\t\tlabelOpt := common.SelectOption{Label: new(string)}\n\t\t\t\t*labelOpt.Label = item\n\t\t\t\topts = append(opts, &valOpt, &labelOpt)\n\t\t\tcase map[string]any:\n\t\t\t\topt, err := extractSelectOptionFromMap(item)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\n\t\t\t\topts = append(opts, opt)\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"options: expected string or object, got %T\", item)\n\t\t\t}\n\t\t}\n\tcase reflect.Map:\n\t\tvar raw map[string]any\n\t\tif err := rt.ExportTo(values, &raw); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"options: expected object, got %T\", values)\n\t\t}\n\n\t\topt, err := extractSelectOptionFromMap(raw)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\topts = append(opts, opt)\n\tcase reflect.TypeFor[*common.ElementHandle]().Kind():\n\t\topts = append(opts, t.(*common.ElementHandle)) //nolint:forcetypeassert\n\tcase reflect.TypeFor[sobek.Object]().Kind():\n\t\tobj := values.ToObject(rt)","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/mapping.go#L73-L109","documentation":"Thrown by ConvertSelectOptionValues while iterating array items passed to selectOption (Page/Frame/Locator/ElementHandle). Each item must be either a string (matches value or label) or a plain object (common.SelectOption with value/label/index). Any other item type hits the default branch in browser/mapping.go:83 and aborts selection.","triggerScenarios":"page.selectOption('#sel', [1, 2]) (numbers), [true] (booleans), [null] (nullish item), or [() => {}] (functions). Each array item must be 'red', { value: 'red' }, { label: 'Red' }, or { index: 2 }.","commonSituations":"Option lists read from a JSON data file where numeric values were not quoted ([\"1\",\"2\"] vs [1,2]); mixed arrays built by pushing DOM text that occasionally parses to a number; stale schema where the API started returning integers for option values.","solutions":["Convert numeric items to strings before the call: values.map(String).","Wrap non-string items in an option object: { value: String(item) }.","Filter out null/undefined items: values.filter(v => v != null).","Validate each item with typeof before calling selectOption."],"exampleFix":"// before\nawait page.selectOption('#size', data.sizes); // data.sizes = [1, 2, 3]\n\n// after\nawait page.selectOption('#size', data.sizes.map(String));","handlingStrategy":"type-guard","validationCode":"const items = values.filter(v => v != null).map(v => typeof v === 'string' || typeof v === 'object' ? v : String(v));\nawait page.selectOption('#sel', items);","typeGuard":"function isSelectOptionItem(i) {\n  if (typeof i === 'string') return true;\n  if (i == null || typeof i !== 'object' || Array.isArray(i)) return false;\n  return Object.keys(i).every(k => ['value', 'label', 'index'].includes(k));\n}","tryCatchPattern":"try { await page.selectOption('#sel', values); } catch (e) { if (/expected string or object/.test(e.message)) { /* map offending items to strings and retry */ } throw e; }","preventionTips":["Map numeric option values to strings at the data boundary.","Filter null/undefined out of option arrays before calling selectOption.","Define a shared normalizer (string | {value|label|index}) and use it everywhere."],"tags":["k6","browser","select-option","type-validation","array-items"],"backgroundTag":"invalid-argument-value","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"}