{"record":{"id":"6ada643723ce1f39","repo":"grafana/k6","slug":"options-expected-array-got-t","errorCode":null,"errorMessage":"options: expected array, got %T","messagePattern":"options: expected array, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/mapping.go","lineNumber":71,"sourceCode":"\tcopts.Strict = parseStrict(rt, opts)\n\n\treturn copts, nil\n}\n\nfunc ConvertSelectOptionValues(rt *sobek.Runtime, values sobek.Value) ([]any, error) {\n\tif k6common.IsNullish(values) {\n\t\treturn nil, nil\n\t}\n\n\tvar (\n\t\topts []any\n\t\tt    = values.Export()\n\t)\n\tswitch values.ExportType().Kind() {\n\tcase reflect.Slice:\n\t\tvar sl []any\n\t\tif err := rt.ExportTo(values, &sl); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"options: expected array, got %T\", values)\n\t\t}\n\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)","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/mapping.go#L53-L89","documentation":"Thrown by ConvertSelectOptionValues (browser/mapping.go:63), the shared converter for selectOption values on Page, Frame, Locator, and ElementHandle. After classifying the argument as an array (reflect.Slice), Sobek's ExportTo into []any failed, so k6 cannot read the array items. With plain JavaScript arrays this conversion practically never fails; the error indicates an array-like value whose items are not exportable.","triggerScenarios":"Passing a Go-bound or Proxy-wrapped array-like value to page.selectOption('#sel', values) where Sobek reports slice kind but individual items (functions, Symbols) cannot be exported; arrays whose contents were injected via Go bindings rather than JS literals.","commonSituations":"Using values received from an exported Go binding or a structuredClone/Proxy edge case instead of a plain JS array; extremely rare in normal script usage — when it appears, the argument usually is not the plain array the script author believes it is.","solutions":["Pass a plain array literal: page.selectOption('#sel', ['blue', { label: 'Green' }]).","If the value comes from a binding or JSON, rebuild it in JS first: const values = raw.map(String) or JSON.parse(JSON.stringify(raw)).","Check Array.isArray(values) before calling selectOption.","Pass a single string or object instead of an array if only one option is selected."],"exampleFix":"// before\nawait page.selectOption('#colors', someBoundArrayLike);\n\n// after\nconst values = Array.from(someBoundArrayLike);\nawait page.selectOption('#colors', values);","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(values)) throw new Error('selectOption values must be a plain array');\nawait page.selectOption('#sel', values);","typeGuard":"function isPlainSelectArray(v) {\n  return Array.isArray(v) && v.every(i => typeof i === 'string' || (i != null && typeof i === 'object' && !Array.isArray(i)));\n}","tryCatchPattern":"try { await page.selectOption('#sel', values); } catch (e) { if (/options: expected array/.test(e.message)) { values = Array.from(values); await page.selectOption('#sel', values); } else throw e; }","preventionTips":["Use plain JS array literals for selectOption values.","Rebuild bound/proxied data with Array.from or JSON round-trip before passing it.","Assert Array.isArray on data-driven inputs before the browser call."],"tags":["k6","browser","select-option","type-validation","array"],"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"}