grafana/k6 · error
finding offset position: %w
Error message
finding offset position: %w
What it means
offsetPosition() calls BoundingBox() to anchor an offset-based click/hover point; this error wraps that failure. The wrapped error is usually 'element is not visible: ... Could not compute box model' for hidden, zero-layout, or detached elements.
Source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:443
}
`
opts := evalOptions{
forceCallable: true,
returnByValue: true,
}
result, err := h.evalWithScript(apiCtx, opts, fn)
if err != nil {
return nil, err
}
var border struct{ Top, Left float64 }
if err := convert(result, &border); err != nil {
return nil, fmt.Errorf("converting result (%v of type %t) to border: %w", result, result, err)
}
box, err := h.BoundingBox()
if err != nil {
return nil, fmt.Errorf("finding offset position: %w", err)
}
if box == nil || (border.Left == 0 && border.Top == 0) {
return nil, ErrElementNotVisible
}
// Make point relative to the padding box to align with offsetX/offsetY.
return &Position{
X: box.X + border.Left + offset.X,
Y: box.Y + border.Top + offset.Y,
}, nil
}
func (h *ElementHandle) ownerFrame(apiCtx context.Context) (*Frame, error) {
frameID, err := h.frame.page.getOwnerFrame(apiCtx, h)
if err != nil {
return nil, err
}View on GitHub (pinned to 93accf6570)
Solutions
- Wait for the element to be visible first (waitForSelector state 'visible')
- Re-locate the element right before the action
- Use { force: true } to skip actionability checks when the hidden state is intentional
- Verify the position coordinates fall inside the element's box
Example fix
// before
await handle.click({ position: { x: 5, y: 5 } }); // finding offset position: element is not visible
// after
await page.waitForSelector('#btn', { state: 'visible' });
await (await page.$('#btn')).click({ position: { x: 5, y: 5 } }); Defensive patterns
Strategy: validation
Validate before calling
const box = await handle.boundingBox();
if (!box || box.width === 0 || box.height === 0) {
await page.waitForSelector(sel, { state: 'visible' });
}
await handle.click({ position: { x: 5, y: 5 } }); Try / catch
try {
await handle.click({ position: pos });
} catch (e) {
if (String(e).includes('finding offset position')) {
await handle.click(); // retry at center
} else { throw e; }
} Prevention
- Ensure position coordinates lie inside the element box
- Wait for visible before offset clicks
- Re-locate handles before interacting
When it happens
Trigger: click()/dblclick()/hover() with a `position` option on an element that is display:none, has zero size, was detached, or whose bounding box otherwise cannot be computed.
Common situations: Offset-clicking before the element renders; element inside a collapsed iframe; stale handle after navigation; position coordinates outside the element on tiny elements.
Related errors
- finding clickable point: %w
- converting result (%v of type %t) to border: %w
- scrolling element into view: %w
- node is either not visible or not an HTMLElement: %w
- element is not attached to the DOM
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/1ce202cdf489578d.
Report an issue: GitHub.