{"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":1742,"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":1724,"sourceCodeEnd":1760,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1724-L1760","documentation":"Pointer actions with an explicit opts.Position call offsetPosition to compute the click point. It evaluates getElementBorderWidth in the page, converts the result, and takes the bounding box; failure means that evaluation/conversion failed, the bounding box could not be fetched, or the element was deemed not visible (nil box or zero border → ErrElementNotVisible).","triggerScenarios":"Passing position: { x, y } to click/dblclick/hover/tap on an element that is hidden or has no layout (nil bounding box); border-width evaluation failing because the context was destroyed; offsets relative to a padding box the page keeps re-styling.","commonSituations":"Clicking precise coordinates inside canvas/maps/chart widgets where the center is not the target; positions computed from fixed assumptions that break at different viewport sizes; clicking custom-drawn controls with 0 border width combined with hidden containers.","solutions":["Ensure the element is visible and laid out before using position: waitForSelector(sel, { state: 'visible' })","Validate the box first: const b = el.boundingBox(); only click at position if b is non-null","Omit position to use the element center, which tolerates border quirks better","If coordinates are page-absolute, click with page.mouse.click(x, y) instead of an element-relative position"],"exampleFix":"// before\nel.click({ position: { x: 5, y: 5 } }); // element hidden -> not visible\n\n// after\nconst b = el.boundingBox();\nif (b) {\n  el.click({ position: { x: 5, y: 5 } });\n}","handlingStrategy":"validation","validationCode":"const b = el.boundingBox();\nif (!b || b.width === 0 || b.height === 0) {\n  throw new Error('element has no box; cannot click at a position');\n}\nel.click({ position: { x: 5, y: 5 } });","typeGuard":null,"tryCatchPattern":"try {\n  el.click({ position: { x: 5, y: 5 } });\n} catch (e) {\n  if (String(e).includes('getting element position')) {\n    el.click(); // fall back to the element center\n  } else {\n    throw e;\n  }\n}","preventionTips":["Verify a non-null boundingBox before using the position option","Compute positions relative to the element, not the viewport","Ensure the element is visible and laid out before coordinate clicks"],"tags":["browser","position","bounding-box","actionability","pointer-events"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}