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 NodeId[source]#

Unique DOM node identifier.

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.

node_type: int#

Node’s nodeType.

node_name: str#

Node’s nodeName.

backend_node_id: BackendNodeId#
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 given id once. 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.

node_type: int#

Node’s nodeType.

node_name: str#

Node’s nodeName.

local_name: str#

Node’s localName.

node_value: str#

Node’s nodeValue.

parent_id: Optional[NodeId] = None#

The id of the parent node if any.

child_node_count: Optional[int] = None#

Child count for Container nodes.

children: Optional[List[Node]] = None#

Child nodes of this node when requested with children.

attributes: Optional[List[str]] = None#

Attributes of the Element node in the form of flat array [name1, value1, name2, value2].

document_url: Optional[str] = None#

Document URL that Document or FrameOwner node points to.

base_url: Optional[str] = None#

Base URL that Document or FrameOwner node uses for URL completion.

public_id: Optional[str] = None#

DocumentType’s publicId.

system_id: Optional[str] = None#

DocumentType’s systemId.

internal_subset: Optional[str] = None#

DocumentType’s internalSubset.

xml_version: Optional[str] = None#

Document’s XML version in case of XML documents.

name: Optional[str] = None#

Attr’s name.

value: Optional[str] = None#

Attr’s value.

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.

frame_id: Optional[FrameId] = None#

Frame ID for frame owner elements.

content_document: Optional[Node] = None#

Content document for frame owner elements.

shadow_roots: Optional[List[Node]] = None#

Shadow root list for given element host.

template_content: Optional[Node] = None#

Content document fragment for template elements.

pseudo_elements: Optional[List[Node]] = None#

Pseudo elements associated with this node.

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.

is_svg: Optional[bool] = None#

Whether the node is SVG.

compatibility_mode: Optional[CompatibilityMode] = None#
assigned_slot: Optional[BackendNode] = None#
is_scrollable: Optional[bool] = None#
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.

tree_node: Node#
retained_node_ids: List[NodeId]#
class RGBA(r, g, b, a=None)[source]#

A structure holding an RGBA color.

r: int#

The red component, in the [0-255] range.

g: int#

The green component, in the [0-255] range.

b: int#

The blue component, in the [0-255] range.

a: Optional[float] = None#

1).

Type:

The alpha component, in the [0-1] range (default

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.

content: Quad#

Content box

padding: Quad#

Padding box

border: Quad#

Border box

margin: Quad#

Margin box

width: int#

Node width

height: int#

Node height

shape_outside: Optional[ShapeOutsideInfo] = None#

Shape outside coordinates

class ShapeOutsideInfo(bounds, shape, margin_shape)[source]#

CSS Shape Outside details.

bounds: Quad#

Shape bounds

shape: List[Any]#

Shape coordinate details

margin_shape: List[Any]#

Margin shape bounds

class Rect(x, y, width, height)[source]#

Rectangle.

x: float#

X coordinate

y: float#

Y coordinate

width: float#

Rectangle width

height: float#

Rectangle height

class CSSComputedStyleProperty(name, value)[source]#
name: str#

Computed style property name.

value: str#

Computed style property value.

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

Parameters:

node_id (NodeId) – Id of the node to collect class names.

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[str]]

Returns:

Class name list.

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:
  • node_id (NodeId) – Id of the node to copy.

  • target_node_id (NodeId) – Id of the element to drop the copy into.

  • insert_before_node_id (Optional[NodeId]) – (Optional) Drop the copy before this node (if absent, the copy becomes the last child of `targetNodeId`).

Return type:

Generator[Dict[str, Any], Dict[str, Any], NodeId]

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:

Generator[Dict[str, Any], Dict[str, Any], Node]

Returns:

Node description.

disable()[source]#

Disables DOM agent for the given page.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

discard_search_results(search_id)[source]#

Discards search results from the session with the given id. getSearchResults should no longer be called for that search.

EXPERIMENTAL

Parameters:

search_id (str) – Unique search session identifier.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

enable(include_whitespace=None)[source]#

Enables DOM agent for the given page.

Parameters:

include_whitespace (Optional[str]) – (EXPERIMENTAL) (Optional) Whether to include whitespaces in the children array of returned Nodes.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

focus(node_id=None, backend_node_id=None, object_id=None)[source]#

Focuses the given element.

Parameters:
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

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:
  • node_id (NodeId) – Id of the popover HTMLElement

  • enable (bool) – If true, opens the popover and keeps it open. If false, closes the popover if it was previously force-opened.

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[NodeId]]

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:
Return type:

Generator[Dict[str, Any], Dict[str, Any], NodeId]

Returns:

The anchor element of the given anchor query.

get_attributes(node_id)[source]#

Returns attributes for the specified node.

Parameters:

node_id (NodeId) – Id of the node to retrieve attributes for.

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[str]]

Returns:

An interleaved array of node attribute names and values.

get_box_model(node_id=None, backend_node_id=None, object_id=None)[source]#

Returns boxes for the given node.

Parameters:
Return type:

Generator[Dict[str, Any], Dict[str, Any], BoxModel]

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:

Generator[Dict[str, Any], Dict[str, Any], Optional[NodeId]]

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:
Return type:

Generator[Dict[str, Any], Dict[str, Any], List[Quad]]

Returns:

Quads that describe node layout relative to viewport.

get_detached_dom_nodes()[source]#

Returns list of detached nodes

EXPERIMENTAL

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[DetachedElementInfo]]

Returns:

The list of detached nodes

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:

Generator[Dict[str, Any], Dict[str, Any], Node]

Returns:

Resulting node.

get_element_by_relation(node_id, relation)[source]#

Returns the NodeId of the matched element according to certain relations.

EXPERIMENTAL

Parameters:
  • node_id (NodeId) – Id of the node from which to query the relation.

  • relation (str) – Type of relation to get.

Return type:

Generator[Dict[str, Any], Dict[str, Any], NodeId]

Returns:

NodeId of the element matching the queried relation.

get_file_info(object_id)[source]#

Returns file information for the given File wrapper.

EXPERIMENTAL

Parameters:

object_id (RemoteObjectId) – JavaScript object id of the node wrapper.

Return type:

Generator[Dict[str, Any], Dict[str, Any], str]

Returns:

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:

Generator[Dict[str, Any], Dict[str, Any], List[Node]]

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:

  1. backendNodeId - Resulting node.

  2. 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:

  1. backendNodeId - Resulting node.

  2. frameId - Frame this node belongs to.

  3. 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

Parameters:

node_id (NodeId) – Id of the node to get stack traces for.

Return type:

Generator[Dict[str, Any], Dict[str, Any], Optional[StackTrace]]

Returns:

(Optional) Creation stack trace, if available.

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:

Generator[Dict[str, Any], Dict[str, Any], List[NodeId]]

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:

Generator[Dict[str, Any], Dict[str, Any], str]

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

Parameters:

node_id (NodeId) – Id of the container node to find querying descendants from.

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[NodeId]]

Returns:

Descendant nodes with container queries against the given container.

get_relayout_boundary(node_id)[source]#

Returns the id of the nearest ancestor that is a relayout boundary.

EXPERIMENTAL

Parameters:

node_id (NodeId) – Id of the node.

Return type:

Generator[Dict[str, Any], Dict[str, Any], NodeId]

Returns:

Relayout boundary node id for the given node.

get_search_results(search_id, from_index, to_index)[source]#

Returns search results from given fromIndex to given toIndex from the search with the given identifier.

EXPERIMENTAL

Parameters:
  • search_id (str) – Unique search session identifier.

  • from_index (int) – Start index of the search result to be returned.

  • to_index (int) – End index of the search result to be returned.

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[NodeId]]

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

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[NodeId]]

Returns:

NodeIds of top layer elements

hide_highlight()[source]#

Hides any highlight.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

highlight_node()[source]#

Highlights DOM node.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

highlight_rect()[source]#

Highlights given rectangle.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

mark_undoable_state()[source]#

Marks last undoable state.

EXPERIMENTAL

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

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:
  • node_id (NodeId) – Id of the node to move.

  • target_node_id (NodeId) – Id of the element to drop the moved node into.

  • insert_before_node_id (Optional[NodeId]) – (Optional) Drop node before this one (if absent, the moved node becomes the last child of `targetNodeId`).

Return type:

Generator[Dict[str, Any], Dict[str, Any], NodeId]

Returns:

New id of the moved node.

Searches for a given string in the DOM tree. Use getSearchResults to access search results or cancelSearch to end this search session.

EXPERIMENTAL

Parameters:
  • query (str) – Plain text or query selector or XPath search query.

  • include_user_agent_shadow_dom (Optional[bool]) – (Optional) True to search in user agent shadow DOM.

Return type:

Generator[Dict[str, Any], Dict[str, Any], Tuple[str, int]]

Returns:

A tuple with the following items:

  1. searchId - Unique search session identifier.

  2. 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

Parameters:

path (str) – Path to node in the proprietary format.

Return type:

Generator[Dict[str, Any], Dict[str, Any], NodeId]

Returns:

Id of the node for given path.

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

Parameters:

backend_node_ids (List[BackendNodeId]) – The array of backend node ids.

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[NodeId]]

Returns:

The array of ids of pushed nodes that correspond to the backend ids specified in backendNodeIds.

query_selector(node_id, selector)[source]#

Executes querySelector on a given node.

Parameters:
  • node_id (NodeId) – Id of the node to query upon.

  • selector (str) – Selector string.

Return type:

Generator[Dict[str, Any], Dict[str, Any], NodeId]

Returns:

Query selector result.

query_selector_all(node_id, selector)[source]#

Executes querySelectorAll on a given node.

Parameters:
  • node_id (NodeId) – Id of the node to query upon.

  • selector (str) – Selector string.

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[NodeId]]

Returns:

Query selector result.

redo()[source]#

Re-does the last undone action.

EXPERIMENTAL

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

remove_attribute(node_id, name)[source]#

Removes attribute with given name from an element with given id.

Parameters:
  • node_id (NodeId) – Id of the element to remove attribute from.

  • name (str) – Name of the attribute to remove.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

remove_node(node_id)[source]#

Removes node with given id.

Parameters:

node_id (NodeId) – Id of the node to remove.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

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 setChildNodes events 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:

Generator[Dict[str, Any], Dict[str, Any], None]

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 setChildNodes notifications.

Parameters:

object_id (RemoteObjectId) – JavaScript object id to convert into node.

Return type:

Generator[Dict[str, Any], Dict[str, Any], NodeId]

Returns:

Node id for given object.

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:

Generator[Dict[str, Any], Dict[str, Any], RemoteObject]

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:

Generator[Dict[str, Any], Dict[str, Any], None]

set_attribute_value(node_id, name, value)[source]#

Sets attribute for an element with given id.

Parameters:
  • node_id (NodeId) – Id of the element to set attribute for.

  • name (str) – Attribute name.

  • value (str) – Attribute value.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

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:
  • node_id (NodeId) – Id of the element to set attributes for.

  • text (str) – Text with a number of attributes. Will parse this text using HTML parser.

  • name (Optional[str]) – (Optional) Attribute name to replace with new attributes derived from text in case text parsed successfully.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

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:
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

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

Parameters:

node_id (NodeId) – DOM node id to be accessible by means of $x command line API.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_node_name(node_id, name)[source]#

Sets node name for a node with given id.

Parameters:
  • node_id (NodeId) – Id of the node to set name for.

  • name (str) – New node’s name.

Return type:

Generator[Dict[str, Any], Dict[str, Any], NodeId]

Returns:

New node’s id.

set_node_stack_traces_enabled(enable)[source]#

Sets if stack traces should be captured for Nodes. See Node.getNodeStackTraces. Default is disabled.

EXPERIMENTAL

Parameters:

enable (bool) – Enable or disable.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_node_value(node_id, value)[source]#

Sets node value for a node with given id.

Parameters:
  • node_id (NodeId) – Id of the node to set value for.

  • value (str) – New node’s value.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_outer_html(node_id, outer_html)[source]#

Sets node HTML markup, returns new node id.

Parameters:
  • node_id (NodeId) – Id of the node to set markup for.

  • outer_html (str) – Outer HTML markup to set.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

undo()[source]#

Undoes the last performed action.

EXPERIMENTAL

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

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 AttributeModified(node_id, name, value)[source]#

Fired when Element’s attribute is modified.

node_id: NodeId#

Id of the node that has changed.

name: str#

Attribute name.

value: str#

Attribute value.

class AttributeRemoved(node_id, name)[source]#

Fired when Element’s attribute is removed.

node_id: NodeId#

Id of the node that has changed.

name: str#

A ttribute name.

class CharacterDataModified(node_id, character_data)[source]#

Mirrors DOMCharacterDataModified event.

node_id: NodeId#

Id of the node that has changed.

character_data: str#

New text value.

class ChildNodeCountUpdated(node_id, child_node_count)[source]#

Fired when Container’s child node count has changed.

node_id: NodeId#

Id of the node that has changed.

child_node_count: int#

New node count.

class ChildNodeInserted(parent_node_id, previous_node_id, node)[source]#

Mirrors DOMNodeInserted event.

parent_node_id: NodeId#

Id of the node that has changed.

previous_node_id: NodeId#

Id of the previous sibling.

node: Node#

Inserted node data.

class ChildNodeRemoved(parent_node_id, node_id)[source]#

Mirrors DOMNodeRemoved event.

parent_node_id: NodeId#

Parent id.

node_id: NodeId#

Id of the node that has been removed.

class DistributedNodesUpdated(insertion_point_id, distributed_nodes)[source]#

EXPERIMENTAL

Called when distribution is changed.

insertion_point_id: NodeId#

Insertion point where distributed nodes were updated.

distributed_nodes: List[BackendNode]#

Distributed nodes for given insertion point.

class DocumentUpdated[source]#

Fired when Document has 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.

node_ids: List[NodeId]#

Ids of the nodes for which the inline styles have been invalidated.

class PseudoElementAdded(parent_id, pseudo_element)[source]#

EXPERIMENTAL

Called when a pseudo element is added to an element.

parent_id: NodeId#

Pseudo element’s parent element id.

pseudo_element: Node#

The added pseudo element.

class TopLayerElementsUpdated[source]#

EXPERIMENTAL

Called when top layer elements are changed.

class ScrollableFlagUpdated(node_id, is_scrollable)[source]#

EXPERIMENTAL

Fired when a node’s scrollability state changes.

node_id: NodeId#

The id of the node.

is_scrollable: bool#

If the node is scrollable.

class PseudoElementRemoved(parent_id, pseudo_element_id)[source]#

EXPERIMENTAL

Called when a pseudo element is removed from an element.

parent_id: NodeId#

Pseudo element’s parent element id.

pseudo_element_id: NodeId#

The removed pseudo element id.

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.

parent_id: NodeId#

Parent node id to populate with children.

nodes: List[Node]#

Child nodes array.

class ShadowRootPopped(host_id, root_id)[source]#

EXPERIMENTAL

Called when shadow root is popped from the element.

host_id: NodeId#

Host element id.

root_id: NodeId#

Shadow root id.

class ShadowRootPushed(host_id, root)[source]#

EXPERIMENTAL

Called when shadow root is pushed into the element.

host_id: NodeId#

Host element id.

root: Node#

Shadow root.