SeleniumHQ/selenium · error · Error
Element does not have any client rects
Error message
Element does not have any client rects
What it means
webdriver.chrome.getFirstClientRect in chrome-driver/atoms.js returns the element's first DOMRect from getClientRects(), recomputed relative to the element's border box. If getClientRects() returns an empty list (length 0), it throws this error because there is no rect to normalize — the element has zero rendered geometry. Elements with display:none, an SVG element with no layout, a disconnected/detached element, or an element in a non-rendered <template> all produce an empty client rect list.
Source
Thrown at javascript/chrome-driver/atoms.js:200
var elemClientPos = goog.style.getClientPosition(elem);
return new goog.math.Coordinate(
elemClientPos.x + region.left, elemClientPos.y + region.top);
};
/**
* Returns the first client rect of the given element, relative to the
* element's border box. If the element does not have any client rects,
* throws an error.
*
* @param {!Element} elem The element to use.
* @return {!goog.math.Rect} The first client rect of the given element,
* relative to the element's border box.
*/
webdriver.chrome.getFirstClientRect = function(elem) {
var clientRects = elem.getClientRects();
if (clientRects.length == 0)
throw new Error('Element does not have any client rects');
var clientRect = clientRects[0];
var clientPos = goog.style.getClientPosition(elem);
return new goog.math.Rect(
clientRect.left - clientPos.x, clientRect.top - clientPos.y,
clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
};
/**
* Returns whether the element or any of its descendants would receive a click
* at the given location. Useful for debugging test clicking issues.
*
* @param {!Element} elem The element to use.
* @param {!goog.math.Coordinate} coord The coordinate to use.
* @return {{clickable:boolean, message: (string|undefined)}} Object containing
* a boolean "clickable" property, as to whether it can be clicked, and an
* optional "message" string property, which contains any warning/error
* message.View on GitHub (pinned to aa36b38e69)
Solutions
- Verify the element is rendered (getComputedStyle(elem).display !== 'none' and document.contains(elem)) before calling getFirstClientRect.
- Re-find the element if it may have been detached, then retry.
- For SVG/non-HTML elements, use getBoundingClientRect() with a fallback or a different geometry source.
- Add a small wait/retry for elements still undergoing layout insertion.
Example fix
// before
var rect = webdriver.chrome.getFirstClientRect(elem) // throws if no client rects
// after
if (document.contains(elem) && elem.getClientRects().length > 0) {
var rect = webdriver.chrome.getFirstClientRect(elem)
} else {
// element not laid out; wait or fall back
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!document.contains(elem) || elem.getClientRects().length === 0) {
// element not laid out; do not call getFirstClientRect
return null
} Type guard
function hasClientRects(elem) {
return !!elem && document.contains(elem) && elem.getClientRects().length > 0
} Try / catch
try {
rect = webdriver.chrome.getFirstClientRect(elem)
} catch (e) {
if (/does not have any client rects/.test(e.message)) { /* wait/re-find */ }
else throw e
} Prevention
- Verify display !== 'none' and document.contains(elem) before calling.
- Re-find elements suspected of being detached/stale.
- For SVG/template nodes, use an alternate geometry source.
- Allow a brief layout settle after inserting elements.
When it happens
Trigger: Calling getFirstClientRect on an element with display:none or visibility:hidden in some engines. Calling it on a detached element not attached to the document. Calling it on an SVG/foreignObject or <template> content node that has no layout box. Calling it before the element has been laid out (e.g. immediately after insertion in a synchronous script).
Common situations: Chrome-driver click/coordinate computation invoked against an element that was hidden or detached between findElement and the action. Race conditions where the element is removed from the DOM (StaleElement) but the rect call still runs. SVG elements that render no box. Elements inside display:none containers.
Related errors
- Argument to isShown must be of type Element
- Argument to isShown must be of type Element
- Expected input and output file paths
- Expected input and output file paths
- Unexpected compiled output format. Expected it to start with
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/d514dda7192ad1d9.
Report an issue: GitHub.