grafana/k6 · error

checking element: %w

Error message

checking element: %w

What it means

ElementHandle.SetChecked() (and Uncheck(), which delegates to it) wraps every failure of the check/uncheck pointer action (element_handle.go:1335). The wrapped error is most often the injected script's 'not a checkbox or radio button' (error:notcheckbox), an actionability timeout (hidden/disabled/unstable element), or a detached handle.

Source

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

		return cmp.Compare(a.index, b.index)
	})

	els := make([]*ElementHandle, 0, len(indexedElems))
	for _, ie := range indexedElems {
		els = append(els, ie.elem)
	}

	return els, nil
}

// SetChecked checks or unchecks an element.
func (h *ElementHandle) SetChecked(checked bool, opts *ElementHandleSetCheckedOptions) error {
	setChecked := func(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {
		return nil, handle.setChecked(apiCtx, checked, p)
	}
	setCheckedAction := h.newPointerAction(setChecked, &opts.ElementHandleBasePointerOptions)
	if _, err := call(h.ctx, setCheckedAction, opts.Timeout); err != nil {
		return fmt.Errorf("checking element: %w", err)
	}

	applySlowMo(h.ctx)

	return nil
}

// Uncheck scrolls element into view, and if it's an input element of type
// checkbox that is already checked, clicks on it to mark it as unchecked.
func (h *ElementHandle) Uncheck(opts *ElementHandleSetCheckedOptions) error {
	return h.SetChecked(false, opts)
}

// Check scrolls element into view, and if it's an input element of type
// checkbox that is unchecked, clicks on it to mark it as checked.
func (h *ElementHandle) Check(opts *ElementHandleSetCheckedOptions) error {
	return h.SetChecked(true, opts)
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Confirm the target is a real input[type=checkbox|radio] (inspect DOM); target the input, not the styled label/span
  2. waitForSelector with state:'visible' first, or raise opts.timeout
  3. If the native input is intentionally visually hidden but functional, use { force: true } or check via label click
  4. Verify enabled state — disabled inputs fail actionability

Example fix

// before
await page.$('.fancy-toggle').check(); // styled span, not the input
// after
await page.$('input[type=checkbox]#consent').check({ timeout: 10_000 });
Defensive patterns

Strategy: validation

Validate before calling

// Verify the target is a real checkbox/radio input before checking
const is = await el.evaluate(n => n.tagName === 'INPUT' && ['checkbox','radio'].includes(n.type));
if (!is) throw new Error('not a checkbox/radio input — use click() for custom controls');

Type guard

const isCheckable = async el => await el.evaluate(n => n.tagName === 'INPUT' && (n.type === 'checkbox' || n.type === 'radio'));

Try / catch

try { await el.check({ timeout: 10_000 }); }
catch (e) {
  if (/checking element/.test(e.message) && /not a checkbox/.test(e.message)) { await el.click(); /* custom control */ }
  else if (/waiting/.test(e.message)) { await page.waitForSelector(sel, { state: 'visible' }); await el.check({ force: true }); }
  else throw e;
}

Prevention

When it happens

Trigger: Calling check() on anything other than input[type=checkbox] or input[type=radio]; the input is hidden (custom-styled controls), disabled, or animating past the timeout; label-wrapped custom checkboxes where the real input is visually hidden.

Common situations: Modern UI kits that hide the native input and style a span — check() times out or Playwright-style force is needed; forms rendered after async fetch with default timeouts too small.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/4ee7f50e6ce4da39. Report an issue: GitHub.