grafana/k6 · error
pressing %q on element: %w
Error message
pressing %q on element: %w
What it means
ElementHandle.Press() wraps every failure of the press action (scroll into view + keyboard down/up) with 'pressing %q on element' (element_handle.go:1179). The wrapped error is typically an actionability timeout (element not visible/stable/enabled within the timeout), an unrecognized key name, or a detached handle — check the inner message for the real cause.
Source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:1179
frame, ok := h.frame.manager.getFrameByID(node.FrameID)
if !ok {
return nil, fmt.Errorf("no frame found for id %s", node.FrameID)
}
return frame, nil
}
// Press scrolls element into view and presses the given keys.
func (h *ElementHandle) Press(key string, opts *ElementHandlePressOptions) error {
press := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
return nil, handle.press(apiCtx, key, KeyboardOptions{})
}
pressAction := h.newAction(
[]string{}, press, false, withRetry, opts.NoWaitAfter, opts.Timeout,
)
if _, err := call(h.ctx, pressAction, opts.Timeout); err != nil {
return fmt.Errorf("pressing %q on element: %w", key, err)
}
applySlowMo(h.ctx)
return nil
}
// Query runs "element.querySelector" within the page. If no element matches the selector,
// the return value resolves to "null".
func (h *ElementHandle) Query(selector string, strict bool) (_ *ElementHandle, rerr error) {
parsedSelector, err := NewSelector(selector)
if err != nil {
return nil, fmt.Errorf("parsing selector %q: %w", selector, err)
}
// Check for frame navigation in the selector
frameNavIndex := h.findFrameNavigationIndex(parsedSelector)
if frameNavIndex != -1 {View on GitHub (pinned to 93accf6570)
Solutions
- Read the wrapped error text: 'timeout ... waiting' means actionability, anything about keys means the key string
- page.waitForSelector(el, { state: 'visible' }) before pressing, or rely on the action's own wait with a larger opts.timeout
- Use canonical key names: 'Enter', 'Tab', 'ArrowDown', 'Control+A'
- If the visibility heuristic misfires (offscreen but interactive), pass { force: true } or scroll into view first
Example fix
// before
await page.$('input').press('enter'); // wrong casing + no wait
// after
const input = await page.waitForSelector('input', { state: 'visible' });
await input.press('Enter', { timeout: 10_000 }); Defensive patterns
Strategy: validation
Validate before calling
// Fail fast on bad keys before calling the API
const KEYS = new Set(['Enter','Tab','Escape','ArrowDown','ArrowUp','ArrowLeft','ArrowRight','Home','End','PageUp','PageDown','Delete','Backspace']);
const norm = k => k.length === 1 ? k : KEYS.has(k) ? k : (() => { throw new Error(`invalid key: ${k}`); })(); Try / catch
try { await el.press('Enter', { timeout: 10_000 }); }
catch (e) {
if (/pressing .* on element/.test(e.message) && /waiting/.test(e.message)) { await page.waitForSelector(sel, { state: 'visible' }); await el.press('Enter'); }
else throw e;
} Prevention
- waitForSelector visible before press
- Use canonical key names ('Enter', 'Control+A')
- Set explicit timeouts sized to the page under load
When it happens
Trigger: Pressing a key on an element that is hidden, zero-sized, animating, disabled, or detached; passing an invalid key string (e.g. 'enter' instead of 'Enter', or malformed modifiers); a timeout smaller than the page's render time under load.
Common situations: Pressing Enter on inputs/buttons that appear after async fetch; default timeouts too short when k6 load slows the page; key names copied from a different automation library's convention.
Related errors
- pressing %q on %q: %w
- typing %q in %q: %w
- clicking on element: %w
- double clicking on element: %w
- filling element: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/75546185e9bef14f.
Report an issue: GitHub.