{"record":{"id":"1ce202cdf489578d","repo":"grafana/k6","slug":"finding-offset-position-w","errorCode":null,"errorMessage":"finding offset position: %w","messagePattern":"finding offset position: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":443,"sourceCode":"\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tresult, err := h.evalWithScript(apiCtx, opts, fn)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar border struct{ Top, Left float64 }\n\tif err := convert(result, &border); err != nil {\n\t\treturn nil, fmt.Errorf(\"converting result (%v of type %t) to border: %w\", result, result, err)\n\t}\n\n\tbox, err := h.BoundingBox()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"finding offset position: %w\", err)\n\t}\n\n\tif box == nil || (border.Left == 0 && border.Top == 0) {\n\t\treturn nil, ErrElementNotVisible\n\t}\n\n\t// Make point relative to the padding box to align with offsetX/offsetY.\n\treturn &Position{\n\t\tX: box.X + border.Left + offset.X,\n\t\tY: box.Y + border.Top + offset.Y,\n\t}, nil\n}\n\nfunc (h *ElementHandle) ownerFrame(apiCtx context.Context) (*Frame, error) {\n\tframeID, err := h.frame.page.getOwnerFrame(apiCtx, h)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L425-L461","documentation":"In offsetPosition(), after border widths were read, BoundingBox() failed for the element, so the offset position cannot be anchored. The wrapped error is the underlying bounding-box failure — typically ErrElementNotVisible ('Could not compute box model'), ErrElementNotAttachedToDOM, or a CDP error.","triggerScenarios":"Calling a pointer action with a pos offset on an element that is hidden (display:none/visibility:hidden), zero-sized, or detached between the border read and the box read; also when the page/session dies mid-action.","commonSituations":"Offset clicks on elements inside collapsed containers, hidden tabs, or animating elements measured before layout settles; stale element handles reused after navigation.","solutions":["Wait for the element to be visible and stable before using offsets: await el.waitFor({ state: 'visible' })","Scroll it into view first: await el.scrollIntoViewIfNeeded()","Drop the offset and use a plain center click if the exact point isn't essential","Re-query the element after any navigation instead of reusing handles"],"exampleFix":"// before\nawait el.click({ pos: { x: 5, y: 5 } });\n\n// after\nawait el.scrollIntoViewIfNeeded();\nawait el.waitFor({ state: 'visible' });\nawait el.click({ pos: { x: 5, y: 5 } });","handlingStrategy":"validation","validationCode":"await el.scrollIntoViewIfNeeded();\nawait el.waitFor({ state: 'visible' });\nconst box = await el.boundingBox();\nif (!box) throw new Error('element has no box; cannot use pos offset');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wait for visible and scroll into view before offset clicks","Prefer center clicks unless the exact point matters"],"tags":["browser","click","offset","bounding-box","element-not-visible"],"backgroundTag":"element-not-visible","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}