{"record":{"id":"0de9eacbe078e5e5","repo":"grafana/k6","slug":"getting-element-position-w","errorCode":null,"errorMessage":"getting element position: %w","messagePattern":"getting element position: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1746,"sourceCode":"\t\t\t}\n\t\t\terr = h.scrollRectIntoViewIfNeeded(apiCtx, rect)\n\t\t} else {\n\t\t\t_, err = h.eval(\n\t\t\t\tapiCtx,\n\t\t\t\tevalOptions{forceCallable: true, returnByValue: false},\n\t\t\t\tjs.ScrollIntoView,\n\t\t\t\tsopts,\n\t\t\t)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"scrolling element into view: %w\", err)\n\t\t}\n\n\t\t// Get the clickable point\n\t\tif p != nil {\n\t\t\tp, err = h.offsetPosition(apiCtx, opts.Position)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"getting element position: %w\", err)\n\t\t\t}\n\t\t} else {\n\t\t\tp, err = h.clickablePoint()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"pointer action: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\t// Further translation of the point might be necessary if the point\n\t\t// is still relative to the parent frame it is in and not the page.\n\t\t*p, err = h.translatePointToPage(apiCtx, *p)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"translating point to page: %w\", err)\n\t\t}\n\n\t\t// Do a final actionability check to see if element can receive events\n\t\t// at mouse position in question\n\t\tif !opts.Force {","sourceCodeStart":1728,"sourceCodeEnd":1764,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1728-L1764","documentation":"Stage of the k6 browser module's pointer-action pipeline that runs when opts.Position is set: offsetPosition computes the absolute click/tap point from the user-supplied offset relative to the element. This error wraps that computation failing — typically because the element's bounding box could not be obtained (hidden, no layout, detached) or the containing element is not queryable.","triggerScenarios":"click({ position: { x: 10, y: 10 } }) or tap({ position }) on an element whose bounding box cannot be resolved at action time — display:none, zero-size, detached — or with offsets outside the element's box on a re-rendered node.","commonSituations":"Clicking a specific spot on a canvas/map/image that is lazily rendered or resized at action time; offsets tuned against a different viewport than the test's (responsive layouts shift coordinates).","solutions":["Wait for the element to be visible and have a size: waitForSelector(sel, { state: 'visible' }) and confirm via el.boundingBox() in a retry loop if needed.","Verify the offset lies within the element's current bounding box; recompute from el.boundingBox() rather than hardcoding.","Set an explicit viewport matching the layout the offsets were designed for.","Drop the custom position and click the center if the spot does not matter."],"exampleFix":"// before\nconst el = await page.$('#map');\nawait el.click({ position: { x: 320, y: 240 } }); // map not rendered yet -> no box\n\n// after\nconst el = await page.waitForSelector('#map', { state: 'visible' });\nconst box = await el.boundingBox();\nif (box && box.width > 0) {\n  await el.click({ position: { x: Math.min(320, box.width - 1), y: Math.min(240, box.height - 1) } });\n}","handlingStrategy":"validation","validationCode":"const box = await el.boundingBox();\nif (!box || box.width <= 0 || box.height <= 0) {\n  throw new Error('element has no rendered box; cannot use position offset');\n}\nconst x = Math.min(offsetX, box.width - 1);\nconst y = Math.min(offsetY, box.height - 1);\nawait el.click({ position: { x, y } });","typeGuard":"async function hasUsableBox(el) {\n  const b = await el.boundingBox().catch(() => null);\n  return !!b && b.width > 0 && b.height > 0;\n}","tryCatchPattern":"try {\n  await el.click({ position: { x: offsetX, y: offsetY }, timeout: '30s' });\n} catch (e) {\n  if (String(e).includes('getting element position')) {\n    await el.click(); // fall back to center click\n  } else { throw e; }\n}","preventionTips":["Derive offsets from el.boundingBox() instead of hardcoding pixels.","Pin the viewport so responsive layouts keep coordinates stable."],"tags":["k6","browser","element-handle","pointer-action","position-offset"],"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"}