{"record":{"id":"f4a26e01e3346c72","repo":"grafana/k6","slug":"unpacking-selected-options-w","errorCode":null,"errorMessage":"unpacking selected options: %w","messagePattern":"unpacking selected options: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1433,"sourceCode":"\n\treturn nil\n}\n\n// SelectOption selects the options matching the given values.\nfunc (h *ElementHandle) SelectOption(values []any, opts *ElementHandleBaseOptions) ([]string, error) {\n\tselectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.selectOption(apiCtx, values)\n\t}\n\tselectOptionAction := h.newAction(\n\t\t[]string{}, selectOption, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tselectedOptions, err := call(h.ctx, selectOptionAction, opts.Timeout)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"selecting options: %w\", err)\n\t}\n\tvar returnVal []string\n\tif err := convert(selectedOptions, &returnVal); err != nil {\n\t\treturn nil, fmt.Errorf(\"unpacking selected options: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn returnVal, nil\n}\n\n// SelectText selects the text of the element.\nfunc (h *ElementHandle) SelectText(opts *ElementHandleBaseOptions) error {\n\tselectText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.selectText(apiCtx)\n\t}\n\tselectTextAction := h.newAction(\n\t\t[]string{}, selectText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tif _, err := call(h.ctx, selectTextAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"selecting text: %w\", err)\n\t}","sourceCodeStart":1415,"sourceCodeEnd":1451,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1415-L1451","documentation":"Internal error in the k6 browser module's ElementHandle.selectOption(). After the in-page selectOptions() evaluation succeeds, the raw result is converted to []string via the generic convert helper. This error means the CDP-returned value could not be converted to the expected Go string slice — an internal marshalling failure, not a page-level condition.","triggerScenarios":"The injected script returns a non-array or an array containing non-string entries (should not happen with the shipped injected_script.js); a k6/browser version mismatch where the Go wrapper and injected script disagree on the return shape; sobek/CDP serialization returning an unexpected remote object type.","commonSituations":"Upgrading k6 to a version whose browser module changed the selectOption return contract while a pinned older chromium/browser binary or cached script is in play; essentially only seen with version skew or a bug in the module itself.","solutions":["Upgrade k6 to the latest patch release so the Go module and injected script versions match: brew upgrade k6 or download the official binary.","If it persists, reproduce with a minimal <select> and report it as a bug to the k6-browser GitHub repo including the k6 version.","As a workaround, drive the selection manually: click the select, then click the desired <option> element."],"exampleFix":"// workaround while hitting the internal conversion bug\nconst select = await page.waitForSelector('select#country');\nawait select.click();\nconst opt = await select.$('option[value=\"de\"]');\nawait opt.click();","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await el.selectOption(['de']);\n} catch (e) {\n  if (String(e).includes('unpacking selected options')) {\n    await el.click();\n    await (await el.$('option[value=\"de\"]')).click(); // manual fallback\n  } else { throw e; }\n}","preventionTips":["Keep k6 and its browser module versions in sync; avoid mixing custom xk6 builds with stock binaries.","Pin a known-good k6 version in CI and retest browser module behavior before upgrading."],"tags":["k6","browser","element-handle","internal","type-conversion"],"backgroundTag":"type-conversion-failed","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}