{"record":{"id":"75546185e9bef14f","repo":"grafana/k6","slug":"pressing-q-on-element-w","errorCode":null,"errorMessage":"pressing %q on element: %w","messagePattern":"pressing %q on element: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1179,"sourceCode":"\n\tframe, ok := h.frame.manager.getFrameByID(node.FrameID)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"no frame found for id %s\", node.FrameID)\n\t}\n\n\treturn frame, nil\n}\n\n// Press scrolls element into view and presses the given keys.\nfunc (h *ElementHandle) Press(key string, opts *ElementHandlePressOptions) error {\n\tpress := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.press(apiCtx, key, KeyboardOptions{})\n\t}\n\tpressAction := h.newAction(\n\t\t[]string{}, press, false, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tif _, err := call(h.ctx, pressAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"pressing %q on element: %w\", key, err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn nil\n}\n\n// Query runs \"element.querySelector\" within the page. If no element matches the selector,\n// the return value resolves to \"null\".\nfunc (h *ElementHandle) Query(selector string, strict bool) (_ *ElementHandle, rerr error) {\n\tparsedSelector, err := NewSelector(selector)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parsing selector %q: %w\", selector, err)\n\t}\n\n\t// Check for frame navigation in the selector\n\tframeNavIndex := h.findFrameNavigationIndex(parsedSelector)\n\tif frameNavIndex != -1 {","sourceCodeStart":1161,"sourceCodeEnd":1197,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1161-L1197","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait page.$('input').press('enter'); // wrong casing + no wait\n// after\nconst input = await page.waitForSelector('input', { state: 'visible' });\nawait input.press('Enter', { timeout: 10_000 });","handlingStrategy":"validation","validationCode":"// Fail fast on bad keys before calling the API\nconst KEYS = new Set(['Enter','Tab','Escape','ArrowDown','ArrowUp','ArrowLeft','ArrowRight','Home','End','PageUp','PageDown','Delete','Backspace']);\nconst norm = k => k.length === 1 ? k : KEYS.has(k) ? k : (() => { throw new Error(`invalid key: ${k}`); })();","typeGuard":null,"tryCatchPattern":"try { await el.press('Enter', { timeout: 10_000 }); }\ncatch (e) {\n  if (/pressing .* on element/.test(e.message) && /waiting/.test(e.message)) { await page.waitForSelector(sel, { state: 'visible' }); await el.press('Enter'); }\n  else throw e;\n}","preventionTips":["waitForSelector visible before press","Use canonical key names ('Enter', 'Control+A')","Set explicit timeouts sized to the page under load"],"tags":["browser","keyboard","actionability","timeout"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}