grafana/k6 · error

checking element is checked

Error message

checking element is checked: %w

What it means

ElementHandle.isChecked() runs waitForElementState(['checked']) with a zero timeout and deliberately ignores ErrTimedOut ('We don't care about timeout errors here!'). Therefore this wrapped error is a hard failure from the injected script or CDP: typically the element handle is detached ('element is not attached to the DOM'), the execution context was destroyed by navigation, or the session is closed.

Solutions

  1. Re-query the element right before checking it, or use a live locator: await page.locator(sel).isChecked()
  2. Wrap in try/catch and treat an error as 'element gone' rather than a hard failure when appropriate
  3. Guard handle freshness: await el.evaluate(e => e.isConnected)
  4. Avoid caching element handles across navigations or async waits

Example fix

// before
const el = await page.$('#agree');
await page.reload();
const checked = await el.isChecked(); // throws: stale handle

// after
await page.reload();
const checked = await page.locator('#agree').isChecked();
Defensive patterns

Strategy: try-catch

Validate before calling

// Use live locators for state checks; null-check for existence
const el = await page.$('#agree');
if (el === null) throw new Error('checkbox no longer in DOM');
const checked = await page.locator('#agree').isChecked();

Try / catch

let checked = false;
try {
  checked = await el.isChecked();
} catch (e) {
  if (/not attached|Execution context|Could not find object/i.test(String(e.message))) {
    checked = await page.locator(sel).isChecked(); // one live re-resolve
  } else throw e;
}

Prevention

When it happens

Trigger: Checking a checkbox handle after the SPA re-rendered and replaced the node; the page navigated between query and check; the element lives in a frame that was closed; the browser/page shut down before the call.

Common situations: React/Vue re-renders swapping checkbox nodes; route changes after caching a handle; logout or popup close mid-iteration; k6 iteration teardown racing the check.

Related errors


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

Appendix: 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 3fcf5388d7)