{"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":1560,"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":1542,"sourceCodeEnd":1578,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1542-L1578","documentation":"Wrapped failure from ElementHandle.Type (elementHandle.type(text)). Type scrolls the element into view, focuses it, and dispatches per-character keyboard events (handle.typ → focus + Keyboard). The wrapped error typically comes from actionability (element not visible/enabled/editable), a detached element, focus failure, or the action timeout. The offending text is included in the message via %q.","triggerScenarios":"Typing into a disabled, readonly, or non-editable control; element re-rendered between query and type (focus fails on detached node); special characters producing key-mapping errors; timeout while the element never becomes actionable; iframe content not ready.","commonSituations":"Typing into inputs enabled only after async validation; React controlled inputs detaching on state change; typing dates into input[type=number] which rejects non-numeric keys; slow login pages in CI.","solutions":["Wait for the element to be editable: el.waitForElementState('enabled') or page.waitForSelector(sel, { state: 'visible' })","For setting a whole value at once, prefer el.fill(text) — it is faster and does not dispatch per-character events","Increase the timeout: el.type(text, { timeout: '30s' })","Verify the input accepts the characters (e.g. do not type letters into input[type=number])"],"exampleFix":"// before\npage.$('#age').type('30 years'); // input[type=number] rejects letters\n\n// after\npage.waitForSelector('#age', { state: 'visible' }).fill('30');","handlingStrategy":"validation","validationCode":"const el = page.waitForSelector('#q', { state: 'visible' });\nel.waitForElementState('enabled', { timeout: '10s' });\nel.type('k6 browser');","typeGuard":null,"tryCatchPattern":"try {\n  el.type(text, { timeout: '20s' });\n} catch (e) {\n  if (String(e).includes('typing text')) {\n    el.fill(text); // whole-value set without per-character events\n  } else {\n    throw e;\n  }\n}","preventionTips":["Wait for enabled/editable before typing","Prefer fill() when you do not need keypress semantics","Match input type to content (no letters into type=number)"],"tags":["browser","keyboard","actionability","element-handle","input"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}