grafana/k6 · error
typing text %q: %w
Error message
typing text %q: %w
What it means
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.
Source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:1560
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 93accf6570)
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])
Example fix
// before
page.$('#age').type('30 years'); // input[type=number] rejects letters
// after
page.waitForSelector('#age', { state: 'visible' }).fill('30'); Defensive patterns
Strategy: validation
Validate before calling
const el = page.waitForSelector('#q', { state: 'visible' });
el.waitForElementState('enabled', { timeout: '10s' });
el.type('k6 browser'); Try / catch
try {
el.type(text, { timeout: '20s' });
} catch (e) {
if (String(e).includes('typing text')) {
el.fill(text); // whole-value set without per-character events
} else {
throw e;
}
} Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- finding clickable point: %w
- filling element: %w
- pressing %q on element: %w
- selecting text: %w
- setting input files: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/d9667af9a02f0ff9.
Report an issue: GitHub.