Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Teamcapybara Capybara IsDisplayed Atom

From Leeroopedia
Knowledge Sources
Domains Testing, Web_Automation
Last Updated 2026-02-12 06:00 GMT

Overview

The isDisplayed atom is a self-contained JavaScript IIFE that determines whether a DOM element is visually displayed to the user, accounting for CSS visibility, opacity, overflow, dimensions, image maps, Shadow DOM, and popover state.

Description

This JavaScript atom returns an isShown(elem, opt_ignoreOpacity) function that performs a comprehensive series of checks to determine element visibility. The core logic lives in the internal isShown_ function, which evaluates the following conditions in order: the BODY element is always considered shown; OPTION and OPTGROUP elements inherit visibility from their parent SELECT; image map elements (MAP/AREA) are shown if the associated image is shown and the area has positive dimensions; hidden inputs and NOSCRIPT elements are never shown; elements with visibility: hidden or visibility: collapse are not shown; elements whose parents have display: none are not shown (traversing the composed DOM including Shadow DOM boundaries); transparent elements (opacity: 0) are not shown unless opacity checking is explicitly ignored; elements with zero or negative dimensions are not shown (with special handling for SVG PATH elements with positive stroke-width); and finally, elements hidden by overflow: hidden on ancestor containers are not shown. The overflow analysis is handled by getOverflowState, which walks ancestor containers to detect underflow and overflow scrolling states.

Usage

This atom is injected into the browser by the Capybara Selenium driver to evaluate element visibility during visible? checks. It is executed via Selenium's JavaScript execution mechanism and is not called directly by end-user test code.

Code Reference

Source Location

Signature

// Top-level IIFE returns:
function isShown(elem, opt_ignoreOpacity)

// Internal functions:
function isShown_(elem, ignoreOpacity, parentsDisplayedFn)
function getOverflowState(elem)
function getClientRect(elem)
function getClientRegion(elem)
function getOpacity(elem)
function getViewportSize(win)
function getAreaRelativeRect_(area)
function maybeFindImageMap_(elem)
function getAncestor(element, matcher)
function isElement(node, opt_tagName)
function getParentNodeInComposedDom(node)

Import

// This atom is loaded by the Capybara Selenium driver internally.
// It is not imported directly; it is injected via executeScript:
driver.execute_script(isDisplayedAtom, element)

I/O Contract

Inputs

Name Type Required Description
elem HTMLElement Yes The DOM element to check for visibility.
opt_ignoreOpacity Boolean No When true, the opacity check is skipped. Defaults to false.

Outputs

Name Type Description
result Boolean Returns true if the element is visually displayed to the user, false otherwise.

Usage Examples

Basic Usage

// The atom is an IIFE that returns the isShown function:
var isShown = (function(){
  // ... atom code ...
})();

// Check if an element is displayed
var element = document.getElementById('my-element');
var visible = isShown(element);          // => true or false

// Check visibility while ignoring opacity
var visibleIgnoringOpacity = isShown(element, true);  // => true or false

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment