grafana/k6 · error

parsing select option values

Error message

parsing select option values: %w

What it means

Thrown synchronously when the values (first) argument to locator.selectOption(values, opts) cannot be converted. The mapping (locator_mapping.go:362-364) calls ConvertSelectOptionValues (browser/mapping.go:50-129) and wraps failures as "parsing select option values: %w". Supported shapes are: a string, an object with value/label/index keys, an array mixing both, or an ElementHandle; anything else yields errors like "options: expected string or object, got float64" or "options: unsupported type ...". This is the most value-sensitive error in the locator mapping — numeric array entries are the classic trigger.

Solutions

  1. Map numeric arrays to strings or option objects: values.map(String) or values.map(v => ({ value: String(v) }))
  2. Use the documented shapes: 'blue', { value: 'blue' }, { label: 'Blue' }, { index: 2 }, or arrays thereof
  3. Convert Set/Map to Array.from(...) before passing
  4. Validate the array contents before the call when data comes from an API response

Example fix

// before
const ids = resp.json().categoryIds; // number[]
await locator.selectOption(ids); // "parsing select option values: options: expected string or object, got float64"

// after
const ids = resp.json().categoryIds.map(String);
await locator.selectOption(ids);
Defensive patterns

Strategy: validation

Validate before calling

function toSelectValues(values) {
  const arr = Array.isArray(values) ? values : [values];
  return arr.map(v => {
    if (typeof v === 'string') return v;
    if (typeof v === 'number' && Number.isInteger(v)) return { index: v };
    if (v instanceof Object && !Array.isArray(v)) {
      if (typeof v.value === 'string' || v.value == null) return v;
      if (v.value !== undefined) return { ...v, value: String(v.value) };
      return v;
    }
    throw new TypeError(`selectOption cannot take ${typeof v}`);
  });
}
await locator.selectOption(toSelectValues(apiIds), { timeout: 5000 });

Type guard

function isSelectValue(v) {
  if (typeof v === 'string') return true;
  if (v && typeof v === 'object' && !Array.isArray(v)) {
    const { value, label, index } = v;
    return (value === undefined || typeof value === 'string') &&
      (label === undefined || typeof label === 'string') &&
      (index === undefined || Number.isInteger(index));
  }
  return false;
}

Try / catch

try {
  await locator.selectOption(values);
} catch (e) {
  if (String(e).includes('parsing select option values'))
    throw new Error(`selectOption values must be strings or {value|label|index} objects, got: ${JSON.stringify(values)}`);
  throw e;
}

Prevention

When it happens

Trigger: locator.selectOption([1, 2]) (numbers instead of strings or {value:...} objects); locator.selectOption(true) or a bare number; an array containing null/booleans; an object whose value/label are not strings (index must be an integer).

Common situations: Selecting options by numeric value attribute read from APIs as JSON numbers: selectOption(data.ids) where ids is number[]; passing a Set or Map instead of an array; porting Playwright tests where a mixed array silently worked because keys were strings.

Related errors


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

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/locator_mapping.go:363

			}), nil
		},
		"inputValue": func(opts sobek.Value) (*sobek.Promise, error) {
			copts, err := parseFrameInputValueOptions(rt, opts, lo.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing input value options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return lo.InputValue(copts) //nolint:wrapcheck
			}), nil
		},
		"selectOption": func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
			copts, err := parseFrameSelectOptionOptions(rt, opts, lo.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing select option options: %w", err)
			}
			convValues, err := ConvertSelectOptionValues(vu.Runtime(), values)
			if err != nil {
				return nil, fmt.Errorf("parsing select option values: %w", err)
			}
			return promise(vu, func() (any, error) {
				return lo.SelectOption(convValues, copts) //nolint:wrapcheck
			}), nil
		},
		"press": func(key string, opts sobek.Value) (*sobek.Promise, error) {
			copts, err := parseFramePressOptions(rt, opts, lo.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing press options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, lo.Press(key, copts) //nolint:wrapcheck
			}), nil
		},

		"pressSequentially": func(text string, opts sobek.Value) (*sobek.Promise, error) {
			copts, err := parseFrameTypeOptions(rt, opts, lo.Timeout())
			if err != nil {

View on GitHub (pinned to 8d06114777)