grafana/k6 · error

parsing selectOption options: %w

Error message

parsing selectOption options: %w

What it means

Thrown synchronously by ElementHandle.selectOption() when the trailing options object fails to parse. It parses common.ElementHandleBaseOptions (force, noWaitAfter, timeout), whose Parse is lenient coercion and always returns nil in common/element_handle_options.go, so this wrap is defensive in current k6. Do not confuse it with error 409, which covers the values argument and fires for real type mismatches.

Source

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

			}), 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
		},
		"setChecked": func(checked bool, opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleSetCheckedOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing setChecked options: %w", err)

View on GitHub (pinned to 93accf6570)

Solutions

  1. Keep the second argument to { force, noWaitAfter, timeout } with numeric milliseconds
  2. Put selection values in the first argument, not the options object
  3. Upgrade k6 if this message appears and retest with an empty options object
  4. Check the wrapped cause after the colon for the failing field

Example fix

// before
await el.selectOption('blue', { timeout: '3s' });

// after
await el.selectOption('blue', { timeout: 3000 });
Defensive patterns

Strategy: try-catch

Validate before calling

const ALLOWED = new Set(['force', 'noWaitAfter', 'timeout']);
const bad = Object.keys(opts || {}).filter(k => !ALLOWED.has(k));
if (bad.length) console.warn(`selectOption(): unsupported options ignored: ${bad.join(', ')}`);
if (opts?.timeout !== undefined && !Number.isFinite(Number(opts.timeout))) {
  throw new Error('selectOption(): timeout must be ms number');
}

Type guard

function isSelectOpts(o) {
  if (o == null) return true;
  return (o.force === undefined || typeof o.force === 'boolean') &&
         (o.noWaitAfter === undefined || typeof o.noWaitAfter === 'boolean') &&
         (o.timeout === undefined || Number.isFinite(o.timeout));
}

Try / catch

try {
  await el.selectOption(values, opts);
} catch (e) {
  if (/parsing selectOption options/.test(String(e.message))) {
    console.log(`fix selectOption options object: ${e.message}`);
  } else throw e; // 'parsing select options values' means the FIRST argument is bad instead
}

Prevention

When it happens

Trigger: In current code none: force/noWaitAfter/timeout coerce any value and unknown keys are ignored. Note that 'state' or other Playwright waitForSelector-style keys passed here are silently ignored, not rejected.

Common situations: Passing a timeout as '3s' (coerced to a wrong number rather than erroring); scripts written against old xk6-browser where the whole options object was structurally exported and could fail on incompatible field types.

Related errors


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