grafana/k6 · error

getting input value of %q: %w

Error message

getting input value of %q: %w

What it means

Thrown by Locator.InputValue() in the k6 browser module when the wrapped frame.inputValue call fails. Strict mode is forced on, so the selector must resolve to exactly one element. Zero matches before the timeout, multiple matches (strict mode violation), or an element that is not <input>/<textarea>/<select> all fail; the wrapped error carries the underlying cause.

Source

Thrown at internal/js/modules/k6/browser/common/locator.go:515

	opts.Strict = true
	s, ok, err := l.frame.textContent(l.selector, opts)
	if err != nil {
		return "", false, fmt.Errorf("getting text content of %q: %w", l.selector, err)
	}

	return s, ok, nil
}

// InputValue returns the element's input value that matches
// the locator's selector with strict mode on.
func (l *Locator) InputValue(opts *FrameInputValueOptions) (string, error) {
	l.log.Debugf("Locator:InputValue", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts)

	opts.Strict = true
	v, err := l.frame.inputValue(l.selector, opts)
	if err != nil {
		return "", fmt.Errorf("getting input value of %q: %w", l.selector, err)
	}

	return v, nil
}

// SelectOption filters option values of the first element that matches
// the locator's selector (with strict mode on), selects the options,
// and returns the filtered options.
func (l *Locator) SelectOption(values []any, opts *FrameSelectOptionOptions) ([]string, error) {
	l.log.Debugf("Locator:SelectOption", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts)

	opts.Strict = true
	v, err := l.frame.selectOption(l.selector, values, opts)
	if err != nil {
		return nil, fmt.Errorf("selecting option on %q: %w", l.selector, err)
	}

	applySlowMo(l.ctx)

View on GitHub (pinned to 93accf6570)

Solutions

  1. Make the selector unique (add id/data-testid, chain getByName/getByLabel, or use nth()) so exactly one element matches
  2. await locator.waitFor() before calling inputValue() so the element exists
  3. Confirm the target element is an <input>, <textarea>, or <select>
  4. Increase opts.timeout if the element appears late in the page lifecycle

Example fix

// before
const v = await page.locator('input').inputValue(); // multiple inputs -> strict mode violation

// after
await page.locator('input[name="email"]').waitFor();
const v = await page.locator('input[name="email"]').inputValue();
Defensive patterns

Strategy: try-catch

Validate before calling

const inputs = await page.$$('input[name="email"]');
if (inputs.length !== 1) {
  throw new Error(`expected 1 input, found ${inputs.length}`);
}
const v = await page.locator('input[name="email"]').inputValue();

Type guard

function isInputLike(el) {
  if (!el) return false;
  const t = el.tagName ? el.tagName.toLowerCase() : '';
  return t === 'input' || t === 'textarea' || t === 'select';
}

Try / catch

try {
  const v = await page.locator(sel).inputValue();
} catch (e) {
  if (/strict mode violation/i.test(e.message)) {
    // selector matched multiple elements: narrow it
  } else if (/timeout/i.test(e.message)) {
    // element never appeared: wait longer or fix selector
  } else { throw e; }
}

Prevention

When it happens

Trigger: locator.inputValue() where the selector matches 0 elements (timeout expires), matches more than 1 element (strict mode violation), or resolves to a non-input element such as <div> or contenteditable.

Common situations: Broad selectors like 'input' or '.field' that match several elements; reading a value before SPA rendering finishes; calling inputValue on a container instead of the actual form control.

Related errors


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