grafana/k6 · error

pressing %q on %q: %w

Error message

pressing %q on %q: %w

What it means

Frame.Press() wraps every failure of the internal press action (waiting for the element, checking actionability, dispatching key events) into 'pressing "<key>" on "<selector>": <cause>'. This is a top-level wrapper, so the real reason is in the appended cause: timeout waiting for the element, element not attached, intercepted input, or a closed frame.

Source

Thrown at internal/js/modules/k6/browser/common/frame.go:1676

	return document.QueryAll(selector)
}

// Page returns page that owns frame.
func (f *Frame) Page() *Page {
	return f.manager.page
}

// ParentFrame returns the parent frame, if one exists.
func (f *Frame) ParentFrame() *Frame {
	return f.parentFrame
}

// Press presses the given key for the first element found that matches the selector.
func (f *Frame) Press(selector, key string, opts *FramePressOptions) error {
	f.log.Debugf("Frame:Press", "fid:%s furl:%q sel:%q key:%q", f.ID(), f.URL(), selector, key)

	if err := f.press(selector, key, opts); err != nil {
		return fmt.Errorf("pressing %q on %q: %w", key, selector, err)
	}

	applySlowMo(f.ctx)

	return nil
}

func (f *Frame) press(selector, key string, opts *FramePressOptions) error {
	press := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
		return nil, handle.press(apiCtx, key, opts.ToKeyboardOptions())
	}
	act := f.newAction(
		selector, DOMElementStateAttached, opts.Strict, press,
		[]string{}, false, withRetry, opts.NoWaitAfter, opts.Timeout,
	)
	if _, err := call(f.ctx, act, opts.Timeout); err != nil {
		return errorFromDOMError(err)
	}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Verify the element exists and is actionable: await frame.waitForSelector(selector, { state: 'visible' }) before press().
  2. Use correct key names ('Enter', 'ArrowDown', 'a', 'Control+A') — single characters or named keys only.
  3. If the element is intentionally covered during the test, pass { force: true } to skip actionability checks, or remove the overlay first.
  4. Increase timeout: frame.press(sel, key, { timeout: 60_000 }).

Example fix

// before
await frame.press('#search', 'Return'); // wrong key name + maybe hidden

// after
await frame.waitForSelector('#search', { state: 'visible' });
await frame.press('#search', 'Enter', { timeout: 60_000 });
Defensive patterns

Strategy: validation

Validate before calling

await frame.waitForSelector(sel, { state: 'visible' });
// validate key name against k6's key set before pressing

Try / catch

try { await frame.press(sel, key); }
catch (e) { if (/pressing .* on/.test(e.message)) { /* inspect wrapped cause: timeout vs intercepted */ } throw e; }

Prevention

When it happens

Trigger: frame.press(selector, key) where the selector matches nothing within opts.timeout (default 30s), the element is not visible/enabled (actionability check fails with force=false), the element is detached mid-press, or the key name is invalid (e.g. 'Return' instead of 'Enter').

Common situations: Pressing on overlay-covered buttons (cookie banners, spinners); wrong key naming; default timeout too short on slow CI; element inside an iframe that navigated away; strict mode violation when the selector matches multiple elements.

Related errors


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