DOM#
This domain exposes DOM read/write operations. Each DOM Node is represented with its mirror object
that has an id. This id can be used to get additional information on the Node, resolve it into
the JavaScript object wrapper, etc. It is important that client receives DOM events only for the
nodes that are known to the client. Backend keeps track of the nodes that were sent to the client
and never sends the same node twice. It is client’s responsibility to collect information about
the nodes that were sent to the client. Note that iframe owner elements will return
corresponding document elements as their child nodes.
Types#
Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.
- class BackendNodeId[source]#
Unique DOM node identifier used to reference a node that may not have been pushed to the front-end.
- class BackendNode(node_type, node_name, backend_node_id)[source]#
Backend node with a friendly name.
-
backend_node_id:
BackendNodeId#
-
backend_node_id:
- class PseudoType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Pseudo element type.
- FIRST_LINE = 'first-line'#
- FIRST_LETTER = 'first-letter'#
- CHECKMARK = 'checkmark'#
- BEFORE = 'before'#
- AFTER = 'after'#
- PICKER_ICON = 'picker-icon'#
- INTEREST_HINT = 'interest-hint'#
- MARKER = 'marker'#
- BACKDROP = 'backdrop'#
- COLUMN = 'column'#
- SELECTION = 'selection'#
- SEARCH_TEXT = 'search-text'#
- TARGET_TEXT = 'target-text'#
- SPELLING_ERROR = 'spelling-error'#
- GRAMMAR_ERROR = 'grammar-error'#
- HIGHLIGHT = 'highlight'#
- FIRST_LINE_INHERITED = 'first-line-inherited'#
- SCROLL_MARKER = 'scroll-marker'#
- SCROLL_MARKER_GROUP = 'scroll-marker-group'#
- SCROLL_BUTTON = 'scroll-button'#
- SCROLLBAR = 'scrollbar'#
- SCROLLBAR_THUMB = 'scrollbar-thumb'#
- SCROLLBAR_BUTTON = 'scrollbar-button'#
- SCROLLBAR_TRACK = 'scrollbar-track'#
- SCROLLBAR_TRACK_PIECE = 'scrollbar-track-piece'#
- SCROLLBAR_CORNER = 'scrollbar-corner'#
- RESIZER = 'resizer'#
- INPUT_LIST_BUTTON = 'input-list-button'#
- VIEW_TRANSITION = 'view-transition'#
- VIEW_TRANSITION_GROUP = 'view-transition-group'#
- VIEW_TRANSITION_IMAGE_PAIR = 'view-transition-image-pair'#
- VIEW_TRANSITION_GROUP_CHILDREN = 'view-transition-group-children'#
- VIEW_TRANSITION_OLD = 'view-transition-old'#
- VIEW_TRANSITION_NEW = 'view-transition-new'#
- PLACEHOLDER = 'placeholder'#
- FILE_SELECTOR_BUTTON = 'file-selector-button'#
- DETAILS_CONTENT = 'details-content'#
- PICKER = 'picker'#
- PERMISSION_ICON = 'permission-icon'#
- class ShadowRootType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Shadow root type.
- USER_AGENT = 'user-agent'#
- OPEN_ = 'open'#
- CLOSED = 'closed'#
- class CompatibilityMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Document compatibility mode.
- QUIRKS_MODE = 'QuirksMode'#
- LIMITED_QUIRKS_MODE = 'LimitedQuirksMode'#
- NO_QUIRKS_MODE = 'NoQuirksMode'#
- class PhysicalAxes(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
ContainerSelector physical axes
- HORIZONTAL = 'Horizontal'#
- VERTICAL = 'Vertical'#
- BOTH = 'Both'#
- class LogicalAxes(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
ContainerSelector logical axes
- INLINE = 'Inline'#
- BLOCK = 'Block'#
- BOTH = 'Both'#
- class ScrollOrientation(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Physical scroll orientation
- HORIZONTAL = 'horizontal'#
- VERTICAL = 'vertical'#
- class Node(node_id, backend_node_id, node_type, node_name, local_name, node_value, parent_id=None, child_node_count=None, children=None, attributes=None, document_url=None, base_url=None, public_id=None, system_id=None, internal_subset=None, xml_version=None, name=None, value=None, pseudo_type=None, pseudo_identifier=None, shadow_root_type=None, frame_id=None, content_document=None, shadow_roots=None, template_content=None, pseudo_elements=None, imported_document=None, distributed_nodes=None, is_svg=None, compatibility_mode=None, assigned_slot=None, is_scrollable=None)[source]#
DOM interaction is implemented in terms of mirror objects that represent the actual DOM nodes. DOMNode is a base node mirror type.
-
node_id:
NodeId# Node identifier that is passed into the rest of the DOM messages as the
nodeId. Backend will only push node with givenidonce. It is aware of all requested nodes and will only fire DOM events for nodes known to the client.
-
backend_node_id:
BackendNodeId# The BackendNodeId for this node.
-
attributes:
Optional[List[str]] = None# Attributes of the
Elementnode in the form of flat array[name1, value1, name2, value2].
-
pseudo_type:
Optional[PseudoType] = None# Pseudo element type for this node.
-
pseudo_identifier:
Optional[str] = None# Pseudo element identifier for this node. Only present if there is a valid pseudoType.
-
shadow_root_type:
Optional[ShadowRootType] = None# Shadow root type.
-
imported_document:
Optional[Node] = None# Deprecated, as the HTML Imports API has been removed (crbug.com/937746). This property used to return the imported document for the HTMLImport links. The property is always undefined now.
-
distributed_nodes:
Optional[List[BackendNode]] = None# Distributed nodes for given insertion point.
-
compatibility_mode:
Optional[CompatibilityMode] = None#
-
assigned_slot:
Optional[BackendNode] = None#
-
node_id:
- class DetachedElementInfo(tree_node, retained_node_ids)[source]#
A structure to hold the top-level node of a detached tree and an array of its retained descendants.
- class Quad(iterable=(), /)[source]#
An array of quad vertices, x immediately followed by y for each point, points clock-wise.
- class BoxModel(content, padding, border, margin, width, height, shape_outside=None)[source]#
Box model.
-
shape_outside:
Optional[ShapeOutsideInfo] = None# Shape outside coordinates
-
shape_outside:
Commands#
Each command is a generator function. The return
type Generator[x, y, z] indicates that the generator
yields arguments of type x, it must be resumed with
an argument of type y, and it returns type z. In
this library, types x and y are the same for all
commands, and z is the return type you should pay attention
to. For more information, see
Getting Started: Commands.
- collect_class_names_from_subtree(node_id)[source]#
Collects class names for the node with given id and all of it’s child nodes.
EXPERIMENTAL
- copy_to(node_id, target_node_id, insert_before_node_id=None)[source]#
Creates a deep copy of the specified node and places it into the target container before the given anchor.
EXPERIMENTAL
- Parameters:
- Return type:
- Returns:
Id of the node clone.
- describe_node(node_id=None, backend_node_id=None, object_id=None, depth=None, pierce=None)[source]#
Describes node given its id, does not require domain to be enabled. Does not start tracking any objects, can be used for automation.
- Parameters:
node_id (
Optional[NodeId]) – (Optional) Identifier of the node.backend_node_id (
Optional[BackendNodeId]) – (Optional) Identifier of the backend node.object_id (
Optional[RemoteObjectId]) – (Optional) JavaScript object id of the node wrapper.depth (
Optional[int]) – (Optional) The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.pierce (
Optional[bool]) – (Optional) Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
- Return type:
- Returns:
Node description.
- discard_search_results(search_id)[source]#
Discards search results from the session with the given id.
getSearchResultsshould no longer be called for that search.EXPERIMENTAL
- focus(node_id=None, backend_node_id=None, object_id=None)[source]#
Focuses the given element.
- Parameters:
node_id (
Optional[NodeId]) – (Optional) Identifier of the node.backend_node_id (
Optional[BackendNodeId]) – (Optional) Identifier of the backend node.object_id (
Optional[RemoteObjectId]) – (Optional) JavaScript object id of the node wrapper.
- Return type:
- force_show_popover(node_id, enable)[source]#
When enabling, this API force-opens the popover identified by nodeId and keeps it open until disabled.
EXPERIMENTAL
- Parameters:
- Return type:
- Returns:
List of popovers that were closed in order to respect popover stacking order.
- get_anchor_element(node_id, anchor_specifier=None)[source]#
Returns the target anchor element of the given anchor query according to https://www.w3.org/TR/css-anchor-position-1/#target.
EXPERIMENTAL
- Parameters:
node_id (
NodeId) – Id of the positioned element from which to find the anchor.anchor_specifier (
Optional[str]) – (Optional) An optional anchor specifier, as defined in https://www.w3.org/TR/css-anchor-position-1/#anchor-specifier. If not provided, it will return the implicit anchor element for the given positioned element.
- Return type:
- Returns:
The anchor element of the given anchor query.
- get_box_model(node_id=None, backend_node_id=None, object_id=None)[source]#
Returns boxes for the given node.
- Parameters:
node_id (
Optional[NodeId]) – (Optional) Identifier of the node.backend_node_id (
Optional[BackendNodeId]) – (Optional) Identifier of the backend node.object_id (
Optional[RemoteObjectId]) – (Optional) JavaScript object id of the node wrapper.
- Return type:
- Returns:
Box model for the node.
- get_container_for_node(node_id, container_name=None, physical_axes=None, logical_axes=None, queries_scroll_state=None, queries_anchored=None)[source]#
Returns the query container of the given node based on container query conditions: containerName, physical and logical axes, and whether it queries scroll-state or anchored elements. If no axes are provided and queriesScrollState is false, the style container is returned, which is the direct parent or the closest element with a matching container-name.
EXPERIMENTAL
- Parameters:
- Return type:
- Returns:
(Optional) The container node for the given node, or null if not found.
- get_content_quads(node_id=None, backend_node_id=None, object_id=None)[source]#
Returns quads that describe node position on the page. This method might return multiple quads for inline nodes.
EXPERIMENTAL
- Parameters:
node_id (
Optional[NodeId]) – (Optional) Identifier of the node.backend_node_id (
Optional[BackendNodeId]) – (Optional) Identifier of the backend node.object_id (
Optional[RemoteObjectId]) – (Optional) JavaScript object id of the node wrapper.
- Return type:
- Returns:
Quads that describe node layout relative to viewport.
- get_document(depth=None, pierce=None)[source]#
Returns the root DOM node (and optionally the subtree) to the caller. Implicitly enables the DOM domain events for the current target.
- Parameters:
depth (
Optional[int]) – (Optional) The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.pierce (
Optional[bool]) – (Optional) Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
- Return type:
- Returns:
Resulting node.
- get_element_by_relation(node_id, relation)[source]#
Returns the NodeId of the matched element according to certain relations.
EXPERIMENTAL
- get_flattened_document(depth=None, pierce=None)[source]#
Returns the root DOM node (and optionally the subtree) to the caller. Deprecated, as it is not designed to work well with the rest of the DOM agent. Use DOMSnapshot.captureSnapshot instead.
Deprecated since version 1.3.
- Parameters:
depth (
Optional[int]) – (Optional) The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.pierce (
Optional[bool]) – (Optional) Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
- Return type:
- Returns:
Resulting node.
Deprecated since version 1.3.
- get_frame_owner(frame_id)[source]#
Returns iframe node that owns iframe with the given domain.
EXPERIMENTAL
- Parameters:
frame_id (
FrameId) –- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[BackendNodeId,Optional[NodeId]]]- Returns:
A tuple with the following items:
backendNodeId - Resulting node.
nodeId - (Optional) Id of the node at given coordinates, only when enabled and requested document.
- get_node_for_location(x, y, include_user_agent_shadow_dom=None, ignore_pointer_events_none=None)[source]#
Returns node id at given location. Depending on whether DOM domain is enabled, nodeId is either returned or not.
- Parameters:
x (
int) – X coordinate.y (
int) – Y coordinate.include_user_agent_shadow_dom (
Optional[bool]) – (Optional) False to skip to the nearest non-UA shadow root ancestor (default: false).ignore_pointer_events_none (
Optional[bool]) – (Optional) Whether to ignore pointer-events: none on elements and hit test them.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[BackendNodeId,FrameId,Optional[NodeId]]]- Returns:
A tuple with the following items:
backendNodeId - Resulting node.
frameId - Frame this node belongs to.
nodeId - (Optional) Id of the node at given coordinates, only when enabled and requested document.
- get_node_stack_traces(node_id)[source]#
Gets stack traces associated with a Node. As of now, only provides stack trace for Node creation.
EXPERIMENTAL
- get_nodes_for_subtree_by_style(node_id, computed_styles, pierce=None)[source]#
Finds nodes with a given computed style in a subtree.
EXPERIMENTAL
- Parameters:
node_id (
NodeId) – Node ID pointing to the root of a subtree.computed_styles (
List[CSSComputedStyleProperty]) – The style to filter nodes by (includes nodes if any of properties matches).pierce (
Optional[bool]) – (Optional) Whether or not iframes and shadow roots in the same target should be traversed when returning the results (default is false).
- Return type:
- Returns:
Resulting nodes.
- get_outer_html(node_id=None, backend_node_id=None, object_id=None, include_shadow_dom=None)[source]#
Returns node’s HTML markup.
- Parameters:
node_id (
Optional[NodeId]) – (Optional) Identifier of the node.backend_node_id (
Optional[BackendNodeId]) – (Optional) Identifier of the backend node.object_id (
Optional[RemoteObjectId]) – (Optional) JavaScript object id of the node wrapper.include_shadow_dom (
Optional[bool]) – (EXPERIMENTAL) (Optional) Include all shadow roots. Equals to false if not specified.
- Return type:
- Returns:
Outer HTML markup.
- get_querying_descendants_for_container(node_id)[source]#
Returns the descendants of a container query container that have container queries against this container.
EXPERIMENTAL
- get_relayout_boundary(node_id)[source]#
Returns the id of the nearest ancestor that is a relayout boundary.
EXPERIMENTAL
- get_search_results(search_id, from_index, to_index)[source]#
Returns search results from given
fromIndexto giventoIndexfrom the search with the given identifier.EXPERIMENTAL
- Parameters:
- Return type:
- Returns:
Ids of the search result nodes.
- get_top_layer_elements()[source]#
Returns NodeIds of current top layer elements. Top layer is rendered closest to the user within a viewport, therefore its elements always appear on top of all other content.
EXPERIMENTAL
- move_to(node_id, target_node_id, insert_before_node_id=None)[source]#
Moves node into the new container, places it before the given anchor.
- Parameters:
- Return type:
- Returns:
New id of the moved node.
- perform_search(query, include_user_agent_shadow_dom=None)[source]#
Searches for a given string in the DOM tree. Use
getSearchResultsto access search results orcancelSearchto end this search session.EXPERIMENTAL
- Parameters:
- Return type:
- Returns:
A tuple with the following items:
searchId - Unique search session identifier.
resultCount - Number of search results.
- push_node_by_path_to_frontend(path)[source]#
Requests that the node is sent to the caller given its path. // FIXME, use XPath
EXPERIMENTAL
- push_nodes_by_backend_ids_to_frontend(backend_node_ids)[source]#
Requests that a batch of nodes is sent to the caller given their backend node ids.
EXPERIMENTAL
- remove_attribute(node_id, name)[source]#
Removes attribute with given name from an element with given id.
- request_child_nodes(node_id, depth=None, pierce=None)[source]#
Requests that children of the node with given id are returned to the caller in form of
setChildNodesevents where not only immediate children are retrieved, but all children down to the specified depth.- Parameters:
node_id (
NodeId) – Id of the node to get children for.depth (
Optional[int]) – (Optional) The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.pierce (
Optional[bool]) – (Optional) Whether or not iframes and shadow roots should be traversed when returning the sub-tree (default is false).
- Return type:
- request_node(object_id)[source]#
Requests that the node is sent to the caller given the JavaScript node object reference. All nodes that form the path from the node to the root are also sent to the client as a series of
setChildNodesnotifications.
- resolve_node(node_id=None, backend_node_id=None, object_group=None, execution_context_id=None)[source]#
Resolves the JavaScript node object for a given NodeId or BackendNodeId.
- Parameters:
node_id (
Optional[NodeId]) – (Optional) Id of the node to resolve.backend_node_id (
Optional[BackendNodeId]) – (Optional) Backend identifier of the node to resolve.object_group (
Optional[str]) – (Optional) Symbolic group name that can be used to release multiple objects.execution_context_id (
Optional[ExecutionContextId]) – (Optional) Execution context in which to resolve the node.
- Return type:
- Returns:
JavaScript object wrapper for given node.
- scroll_into_view_if_needed(node_id=None, backend_node_id=None, object_id=None, rect=None)[source]#
Scrolls the specified rect of the given node into view if not already visible. Note: exactly one between nodeId, backendNodeId and objectId should be passed to identify the node.
- Parameters:
node_id (
Optional[NodeId]) – (Optional) Identifier of the node.backend_node_id (
Optional[BackendNodeId]) – (Optional) Identifier of the backend node.object_id (
Optional[RemoteObjectId]) – (Optional) JavaScript object id of the node wrapper.rect (
Optional[Rect]) – (Optional) The rect to be scrolled into view, relative to the node’s border box, in CSS pixels. When omitted, center of the node will be used, similar to Element.scrollIntoView.
- Return type:
- set_attributes_as_text(node_id, text, name=None)[source]#
Sets attributes on element with given id. This method is useful when user edits some existing attribute value and types in several attribute name/value pairs.
- Parameters:
- Return type:
- set_file_input_files(files, node_id=None, backend_node_id=None, object_id=None)[source]#
Sets files for the given file input element.
- Parameters:
node_id (
Optional[NodeId]) – (Optional) Identifier of the node.backend_node_id (
Optional[BackendNodeId]) – (Optional) Identifier of the backend node.object_id (
Optional[RemoteObjectId]) – (Optional) JavaScript object id of the node wrapper.
- Return type:
- set_inspected_node(node_id)[source]#
Enables console to refer to the node with given id via $x (see Command Line API for more details $x functions).
EXPERIMENTAL
- set_node_stack_traces_enabled(enable)[source]#
Sets if stack traces should be captured for Nodes. See
Node.getNodeStackTraces. Default is disabled.EXPERIMENTAL
Events#
Generally, you do not need to instantiate CDP events yourself. Instead, the API creates events for you and then you use the event’s attributes.
- class CharacterDataModified(node_id, character_data)[source]#
Mirrors
DOMCharacterDataModifiedevent.
- class ChildNodeCountUpdated(node_id, child_node_count)[source]#
Fired when
Container’s child node count has changed.
- class ChildNodeInserted(parent_node_id, previous_node_id, node)[source]#
Mirrors
DOMNodeInsertedevent.
- class DistributedNodesUpdated(insertion_point_id, distributed_nodes)[source]#
EXPERIMENTAL
Called when distribution is changed.
-
distributed_nodes:
List[BackendNode]# Distributed nodes for given insertion point.
-
distributed_nodes:
- class DocumentUpdated[source]#
Fired when
Documenthas been totally updated. Node ids are no longer valid.
- class InlineStyleInvalidated(node_ids)[source]#
EXPERIMENTAL
Fired when
Element’s inline style is modified via a CSS property modification.
- class PseudoElementAdded(parent_id, pseudo_element)[source]#
EXPERIMENTAL
Called when a pseudo element is added to an element.
- class ScrollableFlagUpdated(node_id, is_scrollable)[source]#
EXPERIMENTAL
Fired when a node’s scrollability state changes.
- class PseudoElementRemoved(parent_id, pseudo_element_id)[source]#
EXPERIMENTAL
Called when a pseudo element is removed from an element.
- class SetChildNodes(parent_id, nodes)[source]#
Fired when backend wants to provide client with the missing DOM structure. This happens upon most of the calls requesting node ids.