grafana/k6 · error

selecting text

Error message

selecting text: %w

What it means

Thrown by the k6 browser module's ElementHandle.selectText(). It wraps failure of the selectText action: the timeout expiring before the element is actionable, the element being detached, or the injected script returning a DOM error string (via errorFromDOMError) such as 'node is not an element' or a not-editable/not-selectable indicator.

Solutions

  1. Ensure the element is visible and stable first: await el.waitForElementState('visible', { timeout: '30s' }) before selectText.
  2. Re-query the handle immediately before the call: el = await page.waitForSelector(selector).
  3. Increase the timeout: el.selectText({ timeout: '60s' }).
  4. Pass { force: true } to bypass actionability checks when you know the node is attached.

Example fix

// before
const el = await page.$('#snippet');
await el.selectText(); // fails while accordion section collapsed

// after
await page.click('#section-header'); // expand first
const el = await page.waitForSelector('#snippet', { state: 'visible' });
await el.selectText({ timeout: '30s' });
Defensive patterns

Strategy: try-catch

Validate before calling

const visible = await el.isVisible().catch(() => false);
if (visible) { await el.selectText({ timeout: '30s' }); }

Try / catch

try {
  await el.selectText({ timeout: '30s' });
} catch (e) {
  if (String(e).includes('timed out')) {
    el = await page.waitForSelector(sel, { state: 'visible' });
    await el.selectText({ timeout: '30s' });
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling el.selectText() on a detached or hidden element; on an element whose text cannot be selected (e.g., an <input> where text selection semantics differ); while the page rerenders and invalidates the handle; with the default timeout too short.

Common situations: Attempting selectText on content that a framework re-renders mid-selection; hidden elements behind tabs/accordions not yet expanded; CI slowness causing the actionability retry window to expire.

Related errors


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/4dca02ba57109097. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/element_handle.go:1450

	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 nil

View on GitHub (pinned to 3fcf5388d7)