grafana/k6 · error

clicking on element

Error message

clicking on element: %w

What it means

Top-level failure wrapper for ElementHandle.Click: the whole click action (scroll into view, hit-target check, pointer dispatch) did not complete within opts.Timeout or failed otherwise. The wrapped error carries the actual cause — timeout, interception ('another element is intercepting...'), element not visible, or detached — so read the tail before acting.

Solutions

  1. Read the wrapped cause: 'intercepting' → remove/dismiss the overlay; 'not visible' → wait for visible; 'timed out' → raise the timeout
  2. Wait for actionability explicitly: await el.waitFor({ state: 'visible' }) and await el.scrollIntoViewIfNeeded() before click
  3. Pass a bigger timeout: el.click({ timeout: 30_000 }) or page.setDefaultTimeout(30_000)
  4. If an overlay is decorative and unremovable, use el.click({ force: true }) to bypass the hit-target check

Example fix

// before
await page.locator('#buy').click();

// after
const el = page.locator('#buy');
await el.waitFor({ state: 'visible' });
await el.scrollIntoViewIfNeeded();
await el.click({ timeout: 30_000 });
Defensive patterns

Strategy: retry

Validate before calling

const el = page.locator('#buy');
await el.waitFor({ state: 'visible', timeout: 10_000 });
await el.scrollIntoViewIfNeeded();

Try / catch

try {
  await el.click({ timeout: 10_000 });
} catch (e) {
  const msg = String(e);
  if (/intercepting/.test(msg)) { await el.click({ force: true }); }
  else if (/not visible|timed out/.test(msg)) {
    await el.waitFor({ state: 'visible' });
    await el.click({ timeout: 30_000 });
  } else throw e;
}

Prevention

When it happens

Trigger: el.click() where the element never becomes actionable in the timeout window: overlays intercepting, element animating/moving, hidden, detached by SPA re-render, or the action's call(h.ctx, click, opts.Timeout) hitting the deadline at element_handle.go:842.

Common situations: Cookie banners/modals covering CTAs; buttons disabled or replaced mid-click in React/Vue apps; default timeouts too short on slow CI; clicks immediately after goto before hydration.

Related errors


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

Appendix: source

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

	}
	if err != nil {
		return nil, fmt.Errorf("getting bounding box: %w", err)
	}
	return bbox, nil
}

// Click scrolls element into view and clicks in the center of the element
// TODO: look into making more robust using retries
// (see: https://github.com/microsoft/playwright/blob/master/src/server/dom.ts#L298)
func (h *ElementHandle) Click(opts *ElementHandleClickOptions) error {
	click := h.newPointerAction(
		func(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {
			return nil, handle.click(p, opts.ToMouseClickOptions())
		},
		&opts.ElementHandleBasePointerOptions,
	)
	if _, err := call(h.ctx, click, opts.Timeout); err != nil {
		return fmt.Errorf("clicking on element: %w", err)
	}
	applySlowMo(h.ctx)

	return nil
}

// ContentFrame returns the frame that contains this element.
func (h *ElementHandle) ContentFrame() (*Frame, error) {
	var (
		node *cdp.Node
		err  error
	)
	action := dom.DescribeNode().WithObjectID(h.remoteObject.ObjectID)
	if node, err = action.Do(cdp.WithExecutor(h.ctx, h.session)); err != nil {
		return nil, fmt.Errorf("getting remote node %q: %w", h.remoteObject.ObjectID, err)
	}
	if node == nil || node.FrameID == "" {
		return nil, fmt.Errorf("element is not an iframe")

View on GitHub (pinned to 3fcf5388d7)