grafana/k6 · error

checking element is enabled: %w

Error message

checking element is enabled: %w

What it means

Returned by ElementHandle.isEnabled() when the state probe fails with a non-timeout error. ErrTimedOut is intentionally filtered out (timeout just yields 'not enabled yet' semantics), so this error means the probe itself broke: stale handle, destroyed execution context, CDP transport failure, or closed page/browser.

Source

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

}

// IsEditable checks if the element is editable.
func (h *ElementHandle) IsEditable() (bool, error) {
	ok, err := h.isEditable(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 editable: %w", err)
	}

	return ok, nil
}

// IsEnabled checks if the element is enabled.
func (h *ElementHandle) IsEnabled() (bool, error) {
	ok, err := h.isEnabled(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 enabled: %w", err)
	}

	return ok, nil
}

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

	return ok, nil
}

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

View on GitHub (pinned to 93accf6570)

Solutions

  1. Re-query the handle right before isEnabled()
  2. Wait for the element to be attached
  3. Check the page is still open before probing
  4. try/catch around the probe to separate hard failures from false

Example fix

// before
const enabled = await h.isEnabled(); // stale handle
// after
const el = await page.$('#submit');
const enabled = await el.isEnabled();
Defensive patterns

Strategy: try-catch

Validate before calling

const el = await page.$('#submit');
if (el && (await el.isVisible())) {
  const enabled = await el.isEnabled();
}

Try / catch

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

Prevention

When it happens

Trigger: Calling isEnabled() on a handle detached by re-render; after navigation destroyed the context; after page.close(); when the CDP session dropped.

Common situations: Buttons toggled by framework re-renders invalidating cached handles; probing right after an action that navigates; shutdown races at test end.

Related errors


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