grafana/k6 · error

parsing select options values: %w

Error message

parsing select options values: %w

What it means

Thrown synchronously by ElementHandle.selectOption() when the values argument (not the trailing options object) cannot be converted. ConvertSelectOptionValues in browser/mapping.go accepts a string, an object with value/label/index, an array mixing both, or an ElementHandle; anything else errors with messages like 'options: expected string or object, got <type>', 'options[<key>]: expected string|int, got <type>', or 'options: unsupported type <type>'. This is one of the few parse errors in this mapping that fires routinely.

Source

Thrown at internal/js/modules/k6/browser/browser/element_handle_mapping.go:202

				ab := rt.NewArrayBuffer(bb)

				return &ab, nil
			}), nil
		},
		"scrollIntoViewIfNeeded": func(opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing scrollIntoViewIfNeeded options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.ScrollIntoViewIfNeeded(popts) //nolint:wrapcheck
			}), nil
		},
		"selectOption": func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
			convValues, err := ConvertSelectOptionValues(vu.Runtime(), values)
			if err != nil {
				return nil, fmt.Errorf("parsing select options values: %w", err)
			}
			popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing selectOption options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return eh.SelectOption(convValues, popts) //nolint:wrapcheck
			}), nil
		},
		"selectText": func(opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing selectText options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.SelectText(popts) //nolint:wrapcheck
			}), nil
		},

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass values as strings or { value: 'v' } / { label: 'l' } / { index: 3 } with string strings and integer index
  2. Stringify data-driven values before calling: values.map(String) for value/label keys, parseInt for index
  3. Validate the values array with a helper that enforces string-or-{value,label,index} before the call
  4. Catch synchronously with try/catch; the throw happens before any promise is created

Example fix

// before
await el.selectOption([10, { value: 42 }, { index: '2' }]);

// after
await el.selectOption(['10', { value: '42' }, { index: 2 }]);
Defensive patterns

Strategy: validation

Validate before calling

function validateSelectValues(values) {
  if (values == null) return values;
  const list = Array.isArray(values) ? values : [values];
  for (const v of list) {
    if (typeof v === 'string') continue;
    if (typeof v === 'object' && v !== null && !Array.isArray(v)) {
      for (const [k, raw] of Object.entries(v)) {
        if ((k === 'value' || k === 'label') && typeof raw !== 'string')
          throw new Error(`selectOption(): options[${k}] must be a string`);
        if (k === 'index' && !Number.isInteger(raw))
          throw new Error('selectOption(): options[index] must be an integer');
      }
      continue;
    }
    throw new Error(`selectOption(): values must be string or {value,label,index}, got ${typeof v}`);
  }
  return values;
}

Type guard

function isSelectOptionValue(v) {
  if (typeof v === 'string') return true;
  if (typeof v !== 'object' || v === null || Array.isArray(v)) return false;
  return Object.entries(v).every(([k, raw]) =>
    (k === 'value' || k === 'label') ? typeof raw === 'string'
    : k === 'index' ? Number.isInteger(raw)
    : false);
}

Try / catch

try {
  await el.selectOption(values, opts);
} catch (e) {
  if (/parsing select options values|options: expected|string or object|unsupported type|is not a valid/.test(String(e.message))) {
    console.log(`fix selectOption values: ${e.message}`);
  } else throw e;
}

Prevention

When it happens

Trigger: el.selectOption([10]) (numbers in the array), el.selectOption(true) or el.selectOption(5) (non-string scalar), el.selectOption({ value: 42 }) (value not a string), el.selectOption({ index: '2' }) (index not an int), or an array containing null/booleans: each returns 'options: expected string or object, got ...' or a per-key message.

Common situations: Reading option values from JSON/CSV test data where numbers stay numbers ({ index: 2 } written as string '2', or value keys as IDs); porting Playwright tests that also accept these shapes and silently coerce; mixing label strings and numeric indices in one array built by a data-driven loop.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/23a1abdea018058f. Report an issue: GitHub.