grafana/k6 · error
unpacking selected options
Error message
unpacking selected options: %w
What it means
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.
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.
Example fix
// workaround while hitting the internal conversion bug
const select = await page.waitForSelector('select#country');
await select.click();
const opt = await select.$('option[value="de"]');
await opt.click(); Defensive patterns
Strategy: fallback
Try / catch
try {
await el.selectOption(['de']);
} catch (e) {
if (String(e).includes('unpacking selected options')) {
await el.click();
await (await el.$('option[value="de"]')).click(); // manual fallback
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- getting text content of element: unexpected type %T…
- checking hit target
- checking is in viewport: unexpected type %T
- getting element position
- getting injected script
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/f4a26e01e3346c72.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:1433
return nil
}
// SelectOption selects the options matching the given values.
func (h *ElementHandle) SelectOption(values []any, opts *ElementHandleBaseOptions) ([]string, error) {
selectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
return handle.selectOption(apiCtx, values)
}
selectOptionAction := h.newAction(
[]string{}, selectOption, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,
)
selectedOptions, err := call(h.ctx, selectOptionAction, opts.Timeout)
if err != nil {
return nil, fmt.Errorf("selecting options: %w", err)
}
var returnVal []string
if err := convert(selectedOptions, &returnVal); err != nil {
return nil, fmt.Errorf("unpacking selected options: %w", err)
}
applySlowMo(h.ctx)
return returnVal, nil
}
// SelectText selects the text of the element.
func (h *ElementHandle) SelectText(opts *ElementHandleBaseOptions) error {
selectText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
return nil, handle.selectText(apiCtx)
}
selectTextAction := h.newAction(
[]string{}, selectText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,
)
if _, err := call(h.ctx, selectTextAction, opts.Timeout); err != nil {
return fmt.Errorf("selecting text: %w", err)
}View on GitHub (pinned to 3fcf5388d7)