Skip to main content

Overview

The Element class represents an HTML DOM element and provides methods for interaction, property access, and traversal. Elements are returned by Tab methods like find(), select(), and query_selector_all().
Elements are created by Tab methods. Don’t instantiate Element directly.

Creation

Properties

Node Properties

str
The HTML tag name in lowercase (e.g., ‘div’, ‘button’, ‘a’).
str
Alias for tag.
int
Unique node identifier.
str
Node name (uppercase tag name).
int
Node type number (1 = element, 3 = text, etc.).
str
Value of the node (for text nodes).
str
Local name of the element.

Element Relationships

Element | None
Parent element. Requires calling await element.update() first.
List[Element]
List of child elements. Requires calling await element.update() first.
int
Node ID of the parent element.
int
Number of child nodes.

Attributes

ContraDict
Dictionary-like object containing all HTML attributes (href, src, class, id, etc.).
List[str]
Raw list of attribute names and values.

Special Properties

Tab
Reference to the Tab this element belongs to.
cdp.dom.Node
The DOM tree structure.
List
Shadow root nodes attached to this element.
List[Element]
Children within shadow DOM.
str
Frame identifier if element is in an iframe.

Attribute Access

Access HTML attributes directly on the element:

Methods

click()

Click the element.
Example:

apply()

Apply JavaScript function to this element.
str
required
JavaScript function that receives the element as a parameter. Can be an arrow function or function declaration.
bool
default:"True"
Return the value directly instead of a remote object reference.
Example:

update()

Update element to retrieve latest properties and enable parent/children access.
Example:

get_position()

Get the position and size of the element.
bool
default:"False"
Get absolute position on page instead of viewport-relative.
Returns: Position object with x, y, width, height coordinates. Example:

flash()

Flash the element to highlight it visually.
float
default:"0.5"
Duration in seconds to flash.
Example:

scroll_into_view()

Scroll the element into view.
Example:

mouse_move()

Move mouse to this element.
int
default:"10"
Number of steps for smooth movement.
Example:

mouse_click()

Click on this element using mouse coordinates.

mouse_drag()

Drag this element to a new position.
Tuple[float, float]
required
Target position as (x, y) coordinates.
bool
default:"False"
Whether coordinates are relative to current position.
Example:

save_to_dom()

Save element changes back to the DOM.
Example:

remove_from_dom()

Remove this element from the DOM.
Example:

get_html()

Get the HTML content of the element.
Example:

get_js_attributes()

Get JavaScript properties of the element.
Example:

text_all

Get all text content recursively.

text

Get immediate text content.
Example:

Querying Within Elements

Find child elements within an element:

Traversing the DOM

Shadow DOM

Work with shadow DOM elements:

Examples

Fill and submit a form

Extract data from elements

Interact with dynamic elements

See also