{"record":{"id":"e06560b4bff4a39d","repo":"SeleniumHQ/selenium","slug":"argument-to-isshown-must-be-of-type-element-e06560","errorCode":null,"errorMessage":"Argument to isShown must be of type Element","messagePattern":"Argument to isShown must be of type Element","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/atoms/typescript/is-displayed.ts","lineNumber":370,"sourceCode":"      if ((overflowsX && containerOverflow.x !== 'visible') || (overflowsY && containerOverflow.y !== 'visible')) {\n        if (treatAsFixedPosition) {\n          var docScroll = getScroll(container);\n          if (region.left >= htmlElem.scrollWidth - docScroll.x || region.right >= htmlElem.scrollHeight - docScroll.y) {\n            return 'hidden';\n          }\n        }\n\n        var containerOverflowState = getOverflowState(container);\n        return containerOverflowState === 'hidden' ? 'hidden' : 'scroll';\n      }\n    }\n\n    return 'none';\n  }\n\n  function isShownInternal(elem: Element, ignoreOpacity: boolean, displayedFn: (element: Node) => boolean): boolean {\n    if (!isElement(elem)) {\n      throw new Error('Argument to isShown must be of type Element');\n    }\n\n    if (isElement(elem, 'BODY')) {\n      return true;\n    }\n\n    if (isElement(elem, 'OPTION') || isElement(elem, 'OPTGROUP')) {\n      var select = (elem as Element).closest('select');\n      return !!select && isShownInternal(select, true, displayedFn);\n    }\n\n    var imageMap = maybeFindImageMap(elem);\n    if (imageMap) {\n      return !!imageMap.image && imageMap.rect.width > 0 && imageMap.rect.height > 0 &&\n        isShownInternal(imageMap.image, ignoreOpacity, displayedFn);\n    }\n\n    if (isElement(elem, 'INPUT') && (elem as HTMLInputElement).type.toLowerCase() === 'hidden') {","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/atoms/typescript/is-displayed.ts#L352-L388","documentation":"The TypeScript port of the isShown atom (is-displayed.ts, compiled to bot.dom.typescript.isShown) mirrors the legacy Closure guard: isShownInternal throws when elem is not an Element. This is the modern, Shadow-DOM-aware visibility atom used by Selenium Manager and newer bindings. The guard exists because the body of the function calls elem.closest('select'), getComputedStyle, getClientRects, and offsetParent — all Element-only APIs — so a non-Element would throw a less informative TypeError deeper in.","triggerScenarios":"Calling the compiled isShown against a node that is not an Element (Text, Comment, Document, DocumentFragment, null). Using a sharedId/handle that resolves to a non-element node server-side. Passing a polyfilled or cross-realm object that fails the instanceof Element / isElement check despite looking element-like.","commonSituations":"Same family as the legacy atom: text-node XPath targets, stale cross-frame references, ShadowRoot passed instead of host. Additionally common when consumers of the TS atom pass a serialized element reference from a different execution context (e.g. an iframe's element into the top document's isShown).","solutions":["Guard with isElement(elem) (nodeType === 1) before invoking isShownInternal.","Re-acquire the element in the correct document context so it is a real Element in the realm where isShown runs.","When selecting text nodes, resolve to the parent Element before the visibility call.","Null-check findElement results before forwarding them to the atom."],"exampleFix":"// before\nfunction check(node) {\n  return isShownInternal(node, false, displayedFn) // throws for Text nodes\n}\n\n// after\nfunction check(node) {\n  if (!isElement(node)) {\n    if (node && node.parentElement) node = node.parentElement\n    if (!isElement(node)) return false\n  }\n  return isShownInternal(node, false, displayedFn)\n}","handlingStrategy":"type-guard","validationCode":"if (!isElement(elem)) {\n  elem = elem && elem.parentElement\n}\nif (!isElement(elem)) return false","typeGuard":"function isElement(node, tag) {\n  if (!node || node.nodeType !== 1) return false\n  if (tag) return node.tagName === tag.toUpperCase()\n  return true\n}","tryCatchPattern":null,"preventionTips":["Guard with isElement()/nodeType===1 before invoking the TS isShown atom.","Resolve text-node selections to their parent Element.","Ensure elements are real Elements in the same realm/document context the atom runs in.","Null-check findElement outputs before forwarding."],"tags":["typescript","dom","visibility","isshown","type-validation","atoms"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}