{"record":{"id":"d9667af9a02f0ff9","repo":"grafana/k6","slug":"typing-text-q-w","errorCode":null,"errorMessage":"typing text %q: %w","messagePattern":"typing text %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1564,"sourceCode":"\treturn s, true, nil\n}\n\n// Timeout will return the default timeout or the one set by the user.\n// It's an internal method not to be exposed as a JS API.\nfunc (h *ElementHandle) Timeout() time.Duration {\n\treturn h.DefaultTimeout()\n}\n\n// Type scrolls element into view, focuses element and types text.\nfunc (h *ElementHandle) Type(text string, opts *ElementHandleTypeOptions) error {\n\ttyp := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.typ(apiCtx, text, KeyboardOptions{})\n\t}\n\ttypeAction := h.newAction(\n\t\t[]string{}, typ, false, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tif _, err := call(h.ctx, typeAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"typing text %q: %w\", text, err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn nil\n}\n\n// WaitForElementState waits for the element to reach the given state.\nfunc (h *ElementHandle) WaitForElementState(state string, opts *ElementHandleWaitForElementStateOptions) error {\n\t_, err := h.waitForElementState(h.ctx, []string{state}, opts.Timeout)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"waiting for element state %q: %w\", state, err)\n\t}\n\n\treturn nil\n}\n\n// WaitForSelector waits for the selector to appear in the DOM.","sourceCodeStart":1546,"sourceCodeEnd":1582,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1546-L1582","documentation":"Thrown by the k6 browser module's ElementHandle.type(). It wraps failure of the typing action: focusing the element (element detached/hidden), sending key events through the page Keyboard timing out, or actionability retry exhaustion. The quoted %q in the message echoes the exact text being typed.","triggerScenarios":"Calling el.type('hello') on a detached or hidden element; on an <input> that the framework re-creates on focus (detaching the original); with the default timeout too short on slow pages; typing into a disabled input until it is re-enabled.","commonSituations":"Login forms that re-render on focus/validation invalidating handles; masked/OTP inputs re-created per keystroke in some component libraries; CI slowness exhausting the 30s default.","solutions":["Re-query a fresh handle and prefer fill() for setting values in one shot — it is faster and less sensitive to re-renders.","Wait for the element to be enabled and visible: await el.waitForElementState('enabled', { timeout: '30s' }).","Increase the timeout: el.type('hello', { timeout: '60s' }).","For OTP-style inputs, type into each field with fresh handles or use page.keyboard.type after clicking the field."],"exampleFix":"// before\nconst user = await page.$('#username');\nawait user.type('admin'); // fails: input re-created on focus\n\n// after\nconst user = await page.waitForSelector('#username', { state: 'visible' });\nawait user.fill('admin'); // single action, resilient to re-render","handlingStrategy":"try-catch","validationCode":"const enabled = await el.isEnabled().catch(() => false);\nif (enabled) { await el.type('hello', { timeout: '30s' }); }\n// or prefer fill(): await el.fill('hello');","typeGuard":null,"tryCatchPattern":"try {\n  await el.type(text, { timeout: '30s' });\n} catch (e) {\n  if (String(e).includes('timed out')) {\n    el = await page.waitForSelector(sel, { state: 'visible' });\n    await el.fill(text); // one-shot alternative\n  } else { throw e; }\n}","preventionTips":["Prefer fill() over type() for plain value entry; type() is for per-key behavior.","For inputs recreated on focus, re-query the handle after focusing or type into each fresh field."],"tags":["k6","browser","element-handle","typing","actionability"],"backgroundTag":"browser-action-timeout","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}