grafana/k6 · error
selecting text: %w
Error message
selecting text: %w
What it means
Wrapped failure from ElementHandle.SelectText (k6 browser API elementHandle.selectText()). The inner error comes from running the injected-script selectText in the page plus the action wrapper's actionability retry loop: the element is not a text-editable node, is hidden or detached, or the action exceeded its timeout. The wrapper adds the 'selecting text:' prefix so the failing step is identifiable in the script log.
Source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:1446
if err := convert(selectedOptions, &returnVal); err != nil {
return nil, fmt.Errorf("unpacking selected options: %w", err)
}
applySlowMo(h.ctx)
return returnVal, nil
}
// SelectText selects the text of the element.
func (h *ElementHandle) SelectText(opts *ElementHandleBaseOptions) error {
selectText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
return nil, handle.selectText(apiCtx)
}
selectTextAction := h.newAction(
[]string{}, selectText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,
)
if _, err := call(h.ctx, selectTextAction, opts.Timeout); err != nil {
return fmt.Errorf("selecting text: %w", err)
}
applySlowMo(h.ctx)
return nil
}
// SetInputFiles sets the given files into the input file element.
func (h *ElementHandle) SetInputFiles(files *Files, opts *ElementHandleSetInputFilesOptions) error {
setInputFiles := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
return nil, handle.setInputFiles(apiCtx, files)
}
setInputFilesAction := h.newAction([]string{}, setInputFiles, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout)
if _, err := call(h.ctx, setInputFilesAction, opts.Timeout); err != nil {
return fmt.Errorf("setting input files: %w", err)
}
return nilView on GitHub (pinned to 93accf6570)
Solutions
- Re-acquire the element with page.waitForSelector(sel, { state: 'visible' }) immediately before selectText
- Increase the timeout: el.selectText({ timeout: '60s' })
- Verify the target is an input/textarea/contenteditable element, not a div or span
- If the element is intentionally not actionable yet, wait for it: el.waitForElementState('visible')
Example fix
// before
const el = page.$('#notes');
el.selectText(); // fails: element hidden or not editable
// after
const el = page.waitForSelector('#notes', { state: 'visible' });
if (el && el.isVisible()) {
el.selectText({ timeout: '30s' });
} Defensive patterns
Strategy: try-catch
Validate before calling
const el = page.waitForSelector('#notes', { state: 'visible' });
if (!el || !el.isVisible()) {
throw new Error('#notes is not visible; cannot select text');
} Try / catch
try {
el.selectText({ timeout: '30s' });
} catch (e) {
if (String(e).includes('selecting text')) {
// re-query once: handles can go stale after re-renders
page.waitForSelector('#notes', { state: 'visible' }).selectText();
} else {
throw e;
}
} Prevention
- Always acquire elements with waitForSelector(..., { state: 'visible' }) right before selectText
- Pass an explicit timeout instead of relying on the 30s default
- Only call selectText on input/textarea/contenteditable targets
When it happens
Trigger: Calling handle.selectText() on an element that is not an <input>, <textarea> or [contenteditable] node (injected script returns error:notfillableelement); calling it on a display:none or detached element; the withRetry action loop hitting the timeout (default 30s, or opts.Timeout) while the element never becomes actionable.
Common situations: SPA frameworks (React/Vue) re-rendering and invalidating the handle between query and selectText; textareas hidden behind accordions/tabs opened later; slow CI machines where the default timeout is too short.
Related errors
- filling element: %w
- setting input files: %w
- waiting for element state %q: %w
- element is not attached to the DOM
- finding clickable point: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/4dca02ba57109097.
Report an issue: GitHub.