grafana/k6 · error

selecting options: %w

Error message

selecting options: %w

What it means

ElementHandle.SelectOption() wraps the failure of the select action (element_handle.go:1425). The wrapped error is typically 'element is not a select element' from the injected script, an actionability timeout (select hidden/disabled), or no option matching the provided values/labels.

Source

Thrown at internal/js/modules/k6/browser/common/element_handle.go:1425

		return fmt.Errorf("scrolling element into view: %w", err)
	}

	applySlowMo(h.ctx)

	return nil
}

// SelectOption selects the options matching the given values.
func (h *ElementHandle) SelectOption(values []any, opts *ElementHandleBaseOptions) ([]string, error) {
	selectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
		return handle.selectOption(apiCtx, values)
	}
	selectOptionAction := h.newAction(
		[]string{}, selectOption, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,
	)
	selectedOptions, err := call(h.ctx, selectOptionAction, opts.Timeout)
	if err != nil {
		return nil, fmt.Errorf("selecting options: %w", err)
	}
	var returnVal []string
	if err := convert(selectedOptions, &returnVal); err != nil {
		return nil, fmt.Errorf("unpacking selected options: %w", err)
	}

	applySlowMo(h.ctx)

	return returnVal, nil
}

// SelectText selects the text of the element.
func (h *ElementHandle) SelectText(opts *ElementHandleBaseOptions) error {
	selectText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
		return nil, handle.selectText(apiCtx)
	}
	selectTextAction := h.newAction(
		[]string{}, selectText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,

View on GitHub (pinned to 93accf6570)

Solutions

  1. Confirm the target is a real <select> element; for custom dropdowns use click() sequences instead
  2. Match options exactly: use option value, or the exact label text; trim dynamic strings
  3. waitForSelector visible and wait for options to be populated before selecting
  4. Raise opts.timeout if the form renders slowly

Example fix

// before
await page.$('select#country').selectOption({ label: 'united states' }); // label mismatch
// after
await page.waitForSelector('select#country option[value=us]');
await page.$('select#country').selectOption('us');
Defensive patterns

Strategy: validation

Validate before calling

// Verify it is a real <select> with a matching option before selecting
const ok = await el.evaluate(n => n.tagName === 'SELECT');
if (!ok) throw new Error('not a select element — use click() for custom dropdowns');

Type guard

const isSelect = async el => await el.evaluate(n => n.tagName === 'SELECT');

Try / catch

try { return await el.selectOption('us', { timeout: 10_000 }); }
catch (e) {
  if (/not a select/.test(e.message)) { /* custom dropdown: click-based flow */ }
  else if (/selecting options/.test(e.message)) { await page.waitForSelector(`${sel} option[value=us]`); return await el.selectOption('us'); }
  else throw e;
}

Prevention

When it happens

Trigger: Calling selectOption on a non-<select> element (custom dropdown divs); the select is hidden or disabled; the supplied value/label does not match any option exactly; navigation detaches the element mid-action.

Common situations: Custom dropdown components (need click-based interaction, not selectOption); case/whitespace mismatches in labels; selects populated by async fetch after the call runs.

Related errors


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