grafana/k6 · error

unexpected select element type %T

Error message

unexpected select element type %T

What it means

Internal invariant in frame.selectOption: the value returned by the select action must be a jsHandle (a JSHandle for the <select> element); the Go type assertion failed. This is not caused by user input but by an unexpected CDP evaluation result.

Solutions

  1. Retry the selectOption call once — a transient context race can produce it
  2. Verify k6 and its bundled Chromium are a matched, current release
  3. Reproduce with a minimal script and report to grafana/k6 issues if persistent
  4. Work around via page.evaluate: el.value = 'x'; el.dispatchEvent(new Event('change'))

Example fix

// workaround
page.evaluate("() => { const s = document.querySelector('#country'); s.value = 'DE'; s.dispatchEvent(new Event('change', { bubbles: true })); }");
Defensive patterns

Strategy: try-catch

Try / catch

try {
  page.selectOption(sel, 'DE');
} catch (e) {
  if (String(e).includes('unexpected select element type')) {
    page.evaluate(`() => { const s = document.querySelector('${sel}'); s.value = 'DE'; s.dispatchEvent(new Event('change', { bubbles: true })); }`);
  } else { throw e; }
}

Prevention

When it happens

Trigger: The internal evaluate that performs the selection returned a non-handle value (e.g. a primitive or null) — possible with Chromium/k6 version drift or an internal bug; the selection evaluation itself also returned something abnormal.

Common situations: Essentially never in healthy environments; appears when the browser binary and k6 module disagree on the evaluation protocol, or after a partially failed navigation leaves the action in a weird state.

Related errors


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/dd02a4faa8205f09. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/frame.go:1736

	return v, nil
}

func (f *Frame) selectOption(selector string, values []any, opts *FrameSelectOptionOptions) ([]string, error) {
	selectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
		return handle.selectOption(apiCtx, values)
	}
	act := f.newAction(
		selector, DOMElementStateAttached, opts.Strict, selectOption,
		[]string{}, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,
	)
	v, err := call(f.ctx, act, opts.Timeout)
	if err != nil {
		return nil, errorFromDOMError(err)
	}
	selectHandle, ok := v.(jsHandle)
	if !ok {
		return nil, fmt.Errorf("unexpected select element type %T", v)
	}

	// pack the selected <option> values inside <select> into a slice
	optHandles, err := selectHandle.getProperties()
	if err != nil {
		return nil, fmt.Errorf("getProperties: %w", err)
	}
	vals := make([]string, 0, len(optHandles))
	for _, oh := range optHandles {
		val, err := oh.JSONValue()
		if err != nil {
			return nil, fmt.Errorf("reading value: %w", err)
		}
		vals = append(vals, val)
		if err := oh.dispose(); err != nil {
			return nil, fmt.Errorf("optionHandle.dispose: %w", err)
		}
	}

View on GitHub (pinned to 3fcf5388d7)