grafana/k6 · error

options: expected array, got %T

Error message

options: expected array, got %T

What it means

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.

Solutions

  1. Pass a plain array literal: page.selectOption('#sel', ['blue', { label: 'Green' }]).
  2. 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)).
  3. Check Array.isArray(values) before calling selectOption.
  4. Pass a single string or object instead of an array if only one option is selected.

Example fix

// before
await page.selectOption('#colors', someBoundArrayLike);

// after
const values = Array.from(someBoundArrayLike);
await page.selectOption('#colors', values);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!Array.isArray(values)) throw new Error('selectOption values must be a plain array');
await page.selectOption('#sel', values);

Type guard

function isPlainSelectArray(v) {
  return Array.isArray(v) && v.every(i => typeof i === 'string' || (i != null && typeof i === 'object' && !Array.isArray(i)));
}

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/6ada643723ce1f39. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/mapping.go:71

	copts.Strict = parseStrict(rt, opts)

	return copts, nil
}

func ConvertSelectOptionValues(rt *sobek.Runtime, values sobek.Value) ([]any, error) {
	if k6common.IsNullish(values) {
		return nil, nil
	}

	var (
		opts []any
		t    = values.Export()
	)
	switch values.ExportType().Kind() {
	case reflect.Slice:
		var sl []any
		if err := rt.ExportTo(values, &sl); err != nil {
			return nil, fmt.Errorf("options: expected array, got %T", values)
		}

		for _, item := range sl {
			switch item := item.(type) {
			case string:
				// Strings will match values or labels
				valOpt := common.SelectOption{Value: new(string)}
				*valOpt.Value = item
				labelOpt := common.SelectOption{Label: new(string)}
				*labelOpt.Label = item
				opts = append(opts, &valOpt, &labelOpt)
			case map[string]any:
				opt, err := extractSelectOptionFromMap(item)
				if err != nil {
					return nil, err
				}

				opts = append(opts, opt)

View on GitHub (pinned to 8d06114777)