grafana/k6 · error
typing text
Error message
typing text %q: %w
What it means
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.
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.
Example fix
// before
const user = await page.$('#username');
await user.type('admin'); // fails: input re-created on focus
// after
const user = await page.waitForSelector('#username', { state: 'visible' });
await user.fill('admin'); // single action, resilient to re-render Defensive patterns
Strategy: try-catch
Validate before calling
const enabled = await el.isEnabled().catch(() => false);
if (enabled) { await el.type('hello', { timeout: '30s' }); }
// or prefer fill(): await el.fill('hello'); Try / catch
try {
await el.type(text, { timeout: '30s' });
} catch (e) {
if (String(e).includes('timed out')) {
el = await page.waitForSelector(sel, { state: 'visible' });
await el.fill(text); // one-shot alternative
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- scrolling element into view
- scrolling element into view
- selecting text
- tapping element
- waiting for element state
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/d9667af9a02f0ff9.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:1564
return s, true, nil
}
// Timeout will return the default timeout or the one set by the user.
// It's an internal method not to be exposed as a JS API.
func (h *ElementHandle) Timeout() time.Duration {
return h.DefaultTimeout()
}
// Type scrolls element into view, focuses element and types text.
func (h *ElementHandle) Type(text string, opts *ElementHandleTypeOptions) error {
typ := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
return nil, handle.typ(apiCtx, text, KeyboardOptions{})
}
typeAction := h.newAction(
[]string{}, typ, false, withRetry, opts.NoWaitAfter, opts.Timeout,
)
if _, err := call(h.ctx, typeAction, opts.Timeout); err != nil {
return fmt.Errorf("typing text %q: %w", text, err)
}
applySlowMo(h.ctx)
return nil
}
// WaitForElementState waits for the element to reach the given state.
func (h *ElementHandle) WaitForElementState(state string, opts *ElementHandleWaitForElementStateOptions) error {
_, err := h.waitForElementState(h.ctx, []string{state}, opts.Timeout)
if err != nil {
return fmt.Errorf("waiting for element state %q: %w", state, err)
}
return nil
}
// WaitForSelector waits for the selector to appear in the DOM.View on GitHub (pinned to 3fcf5388d7)