{"record":{"id":"dd02a4faa8205f09","repo":"grafana/k6","slug":"unexpected-select-element-type-t","errorCode":null,"errorMessage":"unexpected select element type %T","messagePattern":"unexpected select element type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":1728,"sourceCode":"\n\treturn v, nil\n}\n\nfunc (f *Frame) selectOption(selector string, values []any, opts *FrameSelectOptionOptions) ([]string, error) {\n\tselectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.selectOption(apiCtx, values)\n\t}\n\tact := f.newAction(\n\t\tselector, DOMElementStateAttached, opts.Strict, selectOption,\n\t\t[]string{}, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tv, err := call(f.ctx, act, opts.Timeout)\n\tif err != nil {\n\t\treturn nil, errorFromDOMError(err)\n\t}\n\tselectHandle, ok := v.(jsHandle)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected select element type %T\", v)\n\t}\n\n\t// pack the selected <option> values inside <select> into a slice\n\toptHandles, err := selectHandle.getProperties()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getProperties: %w\", err)\n\t}\n\tvals := make([]string, 0, len(optHandles))\n\tfor _, oh := range optHandles {\n\t\tval, err := oh.JSONValue()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"reading value: %w\", err)\n\t\t}\n\t\tvals = append(vals, val)\n\t\tif err := oh.dispose(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"optionHandle.dispose: %w\", err)\n\t\t}\n\t}","sourceCodeStart":1710,"sourceCodeEnd":1746,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L1710-L1746","documentation":"After the selectOption action runs, k6 asserts the CDP result is a jsHandle. If the browser returned a primitive value instead of a JSHandle (a protocol/eval-shape mismatch), the type assertion fails and you get 'unexpected select element type <Go type>'. This indicates the internal injected script returned an unexpected shape, typically after a version skew or context switch mid-eval.","triggerScenarios":"selectOption returns a value (nil, string, map) instead of a JSHandle because the evaluation ran in a fresh/replaced execution context (navigation during the call), or the injected script's return contract changed between k6 and the bundled browser binaries.","commonSituations":"Page navigates while selectOption is executing; chromium binary version mismatch after upgrading k6 without a clean build; renderer crash mid-action. Rare — most users will never see it unless the page changes under the action.","solutions":["Re-run the action after the page settles: wait for load state, then call selectOption again.","Upgrade (or pin) k6 so the Go browser module and the chromium binary ship from the same release; clear the browser cache directory if binaries were downloaded separately.","If it reproduces deterministically on one page, capture a trace/DEBUG log and report it — this is an internal contract violation, not a script bug."],"exampleFix":"// before\nawait page.selectOption('#sel', 'a'); // page navigates during call\n\n// after\nawait page.waitForLoadState('load');\nconst v = await page.selectOption('#sel', 'a'); // stable context","handlingStrategy":"retry","validationCode":"await page.waitForLoadState('load'); // ensure stable execution context before selectOption","typeGuard":null,"tryCatchPattern":"try { return await page.selectOption(sel, v); }\ncatch (e) { if (/unexpected select element type/.test(e.message)) { await page.waitForLoadState('load'); return page.selectOption(sel, v); } throw e; }","preventionTips":["Avoid page navigation while selectOption is executing","Keep k6 and its bundled chromium binaries from the same release","Treat this as an internal contract error: report if it reproduces on a static page"],"tags":["browser","select","cdp","type-assertion","internal"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}