grafana/k6 · error

checking element is checked: %w

Error message

checking element is checked: %w

What it means

Returned by ElementHandle.isChecked() when the underlying state probe fails with a non-timeout error. The method calls waitForElementState(['checked']) with a 0 timeout and deliberately ignores ErrTimedOut (a timeout just means 'not checked yet'), so this error only surfaces for real failures: stale handle, destroyed execution context, CDP transport error, or closed browser/page.

Source

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

	v, err := call(h.ctx, inputValueAction, opts.Timeout)
	if err != nil {
		return "", fmt.Errorf("getting element's input value: %w", err)
	}

	s, ok := v.(string)
	if !ok {
		return "", fmt.Errorf("unexpected type %T (expecting string)", v)
	}

	return s, nil
}

// IsChecked checks if a checkbox or radio is checked.
func (h *ElementHandle) IsChecked() (bool, error) {
	ok, err := h.isChecked(h.ctx, 0)
	// We don't care about timeout errors here!
	if err != nil && !errors.Is(err, ErrTimedOut) {
		return false, fmt.Errorf("checking element is checked: %w", err)
	}

	return ok, nil
}

// IsDisabled checks if the element is disabled.
func (h *ElementHandle) IsDisabled() (bool, error) {
	ok, err := h.isDisabled(h.ctx, 0)
	// We don't care anout timeout errors here!
	if err != nil && !errors.Is(err, ErrTimedOut) {
		return false, fmt.Errorf("checking element is disabled: %w", err)
	}

	return ok, nil
}

// IsEditable checks if the element is editable.
func (h *ElementHandle) IsEditable() (bool, error) {

View on GitHub (pinned to 93accf6570)

Solutions

  1. Re-query the handle immediately before isChecked()
  2. Wait for the element: page.waitForSelector(sel, { state: 'attached' })
  3. Ensure the page is still open before probing state
  4. Wrap in try/catch and treat a hard failure separately from a false result

Example fix

// before
const checked = await h.isChecked(); // h captured earlier
// after
const el = await page.$('#agree'); // fresh handle
const checked = await el.isChecked();
Defensive patterns

Strategy: try-catch

Validate before calling

const el = await page.$('#agree');
if (el && (await el.isVisible())) {
  const checked = await el.isChecked();
}

Try / catch

try {
  return await handle.isChecked();
} catch (e) {
  if (String(e).includes('checking element is checked')) {
    const fresh = await page.$(sel);
    return fresh ? fresh.isChecked() : false;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling isChecked() on a handle whose node was detached by a re-render; calling it after the page navigated (context destroyed); calling it after page.close(); CDP session dropped because the browser crashed.

Common situations: Keeping handles from page.$() across iterations of a loop that re-renders the list; checking state after a click navigates away; browser shutdown races at scenario end.

Related errors


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