-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathdom.py
More file actions
2255 lines (1876 loc) · 69.9 KB
/
dom.py
File metadata and controls
2255 lines (1876 loc) · 69.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: DOM
from __future__ import annotations
from cdp.util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
from . import page
from . import runtime
from deprecated.sphinx import deprecated # type: ignore
class NodeId(int):
r'''
Unique DOM node identifier.
'''
def to_json(self) -> int:
return self
@classmethod
def from_json(cls, json: int) -> NodeId:
return cls(json)
def __repr__(self):
return 'NodeId({})'.format(super().__repr__())
class BackendNodeId(int):
r'''
Unique DOM node identifier used to reference a node that may not have been pushed to the
front-end.
'''
def to_json(self) -> int:
return self
@classmethod
def from_json(cls, json: int) -> BackendNodeId:
return cls(json)
def __repr__(self):
return 'BackendNodeId({})'.format(super().__repr__())
class StyleSheetId(str):
r'''
Unique identifier for a CSS stylesheet.
'''
def to_json(self) -> str:
return self
@classmethod
def from_json(cls, json: str) -> StyleSheetId:
return cls(json)
def __repr__(self):
return 'StyleSheetId({})'.format(super().__repr__())
@dataclass
class BackendNode:
r'''
Backend node with a friendly name.
'''
#: ``Node``'s nodeType.
node_type: int
#: ``Node``'s nodeName.
node_name: str
backend_node_id: BackendNodeId
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['nodeType'] = self.node_type
json['nodeName'] = self.node_name
json['backendNodeId'] = self.backend_node_id.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> BackendNode:
return cls(
node_type=int(json['nodeType']),
node_name=str(json['nodeName']),
backend_node_id=BackendNodeId.from_json(json['backendNodeId']),
)
class PseudoType(enum.Enum):
r'''
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"
OVERSCROLL_AREA_PARENT = "overscroll-area-parent"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> PseudoType:
return cls(json)
class ShadowRootType(enum.Enum):
r'''
Shadow root type.
'''
USER_AGENT = "user-agent"
OPEN_ = "open"
CLOSED = "closed"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> ShadowRootType:
return cls(json)
class CompatibilityMode(enum.Enum):
r'''
Document compatibility mode.
'''
QUIRKS_MODE = "QuirksMode"
LIMITED_QUIRKS_MODE = "LimitedQuirksMode"
NO_QUIRKS_MODE = "NoQuirksMode"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> CompatibilityMode:
return cls(json)
class PhysicalAxes(enum.Enum):
r'''
ContainerSelector physical axes
'''
HORIZONTAL = "Horizontal"
VERTICAL = "Vertical"
BOTH = "Both"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> PhysicalAxes:
return cls(json)
class LogicalAxes(enum.Enum):
r'''
ContainerSelector logical axes
'''
INLINE = "Inline"
BLOCK = "Block"
BOTH = "Both"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> LogicalAxes:
return cls(json)
class ScrollOrientation(enum.Enum):
r'''
Physical scroll orientation
'''
HORIZONTAL = "horizontal"
VERTICAL = "vertical"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> ScrollOrientation:
return cls(json)
@dataclass
class Node:
r'''
DOM interaction is implemented in terms of mirror objects that represent the actual DOM nodes.
DOMNode is a base node mirror type.
'''
#: 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.
node_id: NodeId
#: The BackendNodeId for this node.
backend_node_id: BackendNodeId
#: ``Node``'s nodeType.
node_type: int
#: ``Node``'s nodeName.
node_name: str
#: ``Node``'s localName.
local_name: str
#: ``Node``'s nodeValue.
node_value: str
#: The id of the parent node if any.
parent_id: typing.Optional[NodeId] = None
#: Child count for ``Container`` nodes.
child_node_count: typing.Optional[int] = None
#: Child nodes of this node when requested with children.
children: typing.Optional[typing.List[Node]] = None
#: Attributes of the ``Element`` node in the form of flat array ``[name1, value1, name2, value2]``.
attributes: typing.Optional[typing.List[str]] = None
#: Document URL that ``Document`` or ``FrameOwner`` node points to.
document_url: typing.Optional[str] = None
#: Base URL that ``Document`` or ``FrameOwner`` node uses for URL completion.
base_url: typing.Optional[str] = None
#: ``DocumentType``'s publicId.
public_id: typing.Optional[str] = None
#: ``DocumentType``'s systemId.
system_id: typing.Optional[str] = None
#: ``DocumentType``'s internalSubset.
internal_subset: typing.Optional[str] = None
#: ``Document``'s XML version in case of XML documents.
xml_version: typing.Optional[str] = None
#: ``Attr``'s name.
name: typing.Optional[str] = None
#: ``Attr``'s value.
value: typing.Optional[str] = None
#: Pseudo element type for this node.
pseudo_type: typing.Optional[PseudoType] = None
#: Pseudo element identifier for this node. Only present if there is a
#: valid pseudoType.
pseudo_identifier: typing.Optional[str] = None
#: Shadow root type.
shadow_root_type: typing.Optional[ShadowRootType] = None
#: Frame ID for frame owner elements.
frame_id: typing.Optional[page.FrameId] = None
#: Content document for frame owner elements.
content_document: typing.Optional[Node] = None
#: Shadow root list for given element host.
shadow_roots: typing.Optional[typing.List[Node]] = None
#: Content document fragment for template elements.
template_content: typing.Optional[Node] = None
#: Pseudo elements associated with this node.
pseudo_elements: typing.Optional[typing.List[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.
imported_document: typing.Optional[Node] = None
#: Distributed nodes for given insertion point.
distributed_nodes: typing.Optional[typing.List[BackendNode]] = None
#: Whether the node is SVG.
is_svg: typing.Optional[bool] = None
compatibility_mode: typing.Optional[CompatibilityMode] = None
assigned_slot: typing.Optional[BackendNode] = None
is_scrollable: typing.Optional[bool] = None
affected_by_starting_styles: typing.Optional[bool] = None
adopted_style_sheets: typing.Optional[typing.List[StyleSheetId]] = None
is_ad_related: typing.Optional[bool] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['nodeId'] = self.node_id.to_json()
json['backendNodeId'] = self.backend_node_id.to_json()
json['nodeType'] = self.node_type
json['nodeName'] = self.node_name
json['localName'] = self.local_name
json['nodeValue'] = self.node_value
if self.parent_id is not None:
json['parentId'] = self.parent_id.to_json()
if self.child_node_count is not None:
json['childNodeCount'] = self.child_node_count
if self.children is not None:
json['children'] = [i.to_json() for i in self.children]
if self.attributes is not None:
json['attributes'] = [i for i in self.attributes]
if self.document_url is not None:
json['documentURL'] = self.document_url
if self.base_url is not None:
json['baseURL'] = self.base_url
if self.public_id is not None:
json['publicId'] = self.public_id
if self.system_id is not None:
json['systemId'] = self.system_id
if self.internal_subset is not None:
json['internalSubset'] = self.internal_subset
if self.xml_version is not None:
json['xmlVersion'] = self.xml_version
if self.name is not None:
json['name'] = self.name
if self.value is not None:
json['value'] = self.value
if self.pseudo_type is not None:
json['pseudoType'] = self.pseudo_type.to_json()
if self.pseudo_identifier is not None:
json['pseudoIdentifier'] = self.pseudo_identifier
if self.shadow_root_type is not None:
json['shadowRootType'] = self.shadow_root_type.to_json()
if self.frame_id is not None:
json['frameId'] = self.frame_id.to_json()
if self.content_document is not None:
json['contentDocument'] = self.content_document.to_json()
if self.shadow_roots is not None:
json['shadowRoots'] = [i.to_json() for i in self.shadow_roots]
if self.template_content is not None:
json['templateContent'] = self.template_content.to_json()
if self.pseudo_elements is not None:
json['pseudoElements'] = [i.to_json() for i in self.pseudo_elements]
if self.imported_document is not None:
json['importedDocument'] = self.imported_document.to_json()
if self.distributed_nodes is not None:
json['distributedNodes'] = [i.to_json() for i in self.distributed_nodes]
if self.is_svg is not None:
json['isSVG'] = self.is_svg
if self.compatibility_mode is not None:
json['compatibilityMode'] = self.compatibility_mode.to_json()
if self.assigned_slot is not None:
json['assignedSlot'] = self.assigned_slot.to_json()
if self.is_scrollable is not None:
json['isScrollable'] = self.is_scrollable
if self.affected_by_starting_styles is not None:
json['affectedByStartingStyles'] = self.affected_by_starting_styles
if self.adopted_style_sheets is not None:
json['adoptedStyleSheets'] = [i.to_json() for i in self.adopted_style_sheets]
if self.is_ad_related is not None:
json['isAdRelated'] = self.is_ad_related
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Node:
return cls(
node_id=NodeId.from_json(json['nodeId']),
backend_node_id=BackendNodeId.from_json(json['backendNodeId']),
node_type=int(json['nodeType']),
node_name=str(json['nodeName']),
local_name=str(json['localName']),
node_value=str(json['nodeValue']),
parent_id=NodeId.from_json(json['parentId']) if 'parentId' in json else None,
child_node_count=int(json['childNodeCount']) if 'childNodeCount' in json else None,
children=[Node.from_json(i) for i in json['children']] if 'children' in json else None,
attributes=[str(i) for i in json['attributes']] if 'attributes' in json else None,
document_url=str(json['documentURL']) if 'documentURL' in json else None,
base_url=str(json['baseURL']) if 'baseURL' in json else None,
public_id=str(json['publicId']) if 'publicId' in json else None,
system_id=str(json['systemId']) if 'systemId' in json else None,
internal_subset=str(json['internalSubset']) if 'internalSubset' in json else None,
xml_version=str(json['xmlVersion']) if 'xmlVersion' in json else None,
name=str(json['name']) if 'name' in json else None,
value=str(json['value']) if 'value' in json else None,
pseudo_type=PseudoType.from_json(json['pseudoType']) if 'pseudoType' in json else None,
pseudo_identifier=str(json['pseudoIdentifier']) if 'pseudoIdentifier' in json else None,
shadow_root_type=ShadowRootType.from_json(json['shadowRootType']) if 'shadowRootType' in json else None,
frame_id=page.FrameId.from_json(json['frameId']) if 'frameId' in json else None,
content_document=Node.from_json(json['contentDocument']) if 'contentDocument' in json else None,
shadow_roots=[Node.from_json(i) for i in json['shadowRoots']] if 'shadowRoots' in json else None,
template_content=Node.from_json(json['templateContent']) if 'templateContent' in json else None,
pseudo_elements=[Node.from_json(i) for i in json['pseudoElements']] if 'pseudoElements' in json else None,
imported_document=Node.from_json(json['importedDocument']) if 'importedDocument' in json else None,
distributed_nodes=[BackendNode.from_json(i) for i in json['distributedNodes']] if 'distributedNodes' in json else None,
is_svg=bool(json['isSVG']) if 'isSVG' in json else None,
compatibility_mode=CompatibilityMode.from_json(json['compatibilityMode']) if 'compatibilityMode' in json else None,
assigned_slot=BackendNode.from_json(json['assignedSlot']) if 'assignedSlot' in json else None,
is_scrollable=bool(json['isScrollable']) if 'isScrollable' in json else None,
affected_by_starting_styles=bool(json['affectedByStartingStyles']) if 'affectedByStartingStyles' in json else None,
adopted_style_sheets=[StyleSheetId.from_json(i) for i in json['adoptedStyleSheets']] if 'adoptedStyleSheets' in json else None,
is_ad_related=bool(json['isAdRelated']) if 'isAdRelated' in json else None,
)
@dataclass
class DetachedElementInfo:
r'''
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: typing.List[NodeId]
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['treeNode'] = self.tree_node.to_json()
json['retainedNodeIds'] = [i.to_json() for i in self.retained_node_ids]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> DetachedElementInfo:
return cls(
tree_node=Node.from_json(json['treeNode']),
retained_node_ids=[NodeId.from_json(i) for i in json['retainedNodeIds']],
)
@dataclass
class RGBA:
r'''
A structure holding an RGBA color.
'''
#: The red component, in the [0-255] range.
r: int
#: The green component, in the [0-255] range.
g: int
#: The blue component, in the [0-255] range.
b: int
#: The alpha component, in the [0-1] range (default: 1).
a: typing.Optional[float] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['r'] = self.r
json['g'] = self.g
json['b'] = self.b
if self.a is not None:
json['a'] = self.a
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> RGBA:
return cls(
r=int(json['r']),
g=int(json['g']),
b=int(json['b']),
a=float(json['a']) if 'a' in json else None,
)
class Quad(list):
r'''
An array of quad vertices, x immediately followed by y for each point, points clock-wise.
'''
def to_json(self) -> typing.List[float]:
return self
@classmethod
def from_json(cls, json: typing.List[float]) -> Quad:
return cls(json)
def __repr__(self):
return 'Quad({})'.format(super().__repr__())
@dataclass
class BoxModel:
r'''
Box model.
'''
#: Content box
content: Quad
#: Padding box
padding: Quad
#: Border box
border: Quad
#: Margin box
margin: Quad
#: Node width
width: int
#: Node height
height: int
#: Shape outside coordinates
shape_outside: typing.Optional[ShapeOutsideInfo] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['content'] = self.content.to_json()
json['padding'] = self.padding.to_json()
json['border'] = self.border.to_json()
json['margin'] = self.margin.to_json()
json['width'] = self.width
json['height'] = self.height
if self.shape_outside is not None:
json['shapeOutside'] = self.shape_outside.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> BoxModel:
return cls(
content=Quad.from_json(json['content']),
padding=Quad.from_json(json['padding']),
border=Quad.from_json(json['border']),
margin=Quad.from_json(json['margin']),
width=int(json['width']),
height=int(json['height']),
shape_outside=ShapeOutsideInfo.from_json(json['shapeOutside']) if 'shapeOutside' in json else None,
)
@dataclass
class ShapeOutsideInfo:
r'''
CSS Shape Outside details.
'''
#: Shape bounds
bounds: Quad
#: Shape coordinate details
shape: typing.List[typing.Any]
#: Margin shape bounds
margin_shape: typing.List[typing.Any]
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['bounds'] = self.bounds.to_json()
json['shape'] = [i for i in self.shape]
json['marginShape'] = [i for i in self.margin_shape]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ShapeOutsideInfo:
return cls(
bounds=Quad.from_json(json['bounds']),
shape=[i for i in json['shape']],
margin_shape=[i for i in json['marginShape']],
)
@dataclass
class Rect:
r'''
Rectangle.
'''
#: X coordinate
x: float
#: Y coordinate
y: float
#: Rectangle width
width: float
#: Rectangle height
height: float
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['x'] = self.x
json['y'] = self.y
json['width'] = self.width
json['height'] = self.height
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Rect:
return cls(
x=float(json['x']),
y=float(json['y']),
width=float(json['width']),
height=float(json['height']),
)
@dataclass
class CSSComputedStyleProperty:
#: Computed style property name.
name: str
#: Computed style property value.
value: str
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['name'] = self.name
json['value'] = self.value
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSComputedStyleProperty:
return cls(
name=str(json['name']),
value=str(json['value']),
)
def collect_class_names_from_subtree(
node_id: NodeId
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[str]]:
r'''
Collects class names for the node with given id and all of it's child nodes.
**EXPERIMENTAL**
:param node_id: Id of the node to collect class names.
:returns: Class name list.
'''
params: T_JSON_DICT = dict()
params['nodeId'] = node_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'DOM.collectClassNamesFromSubtree',
'params': params,
}
json = yield cmd_dict
return [str(i) for i in json['classNames']]
def copy_to(
node_id: NodeId,
target_node_id: NodeId,
insert_before_node_id: typing.Optional[NodeId] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,NodeId]:
r'''
Creates a deep copy of the specified node and places it into the target container before the
given anchor.
**EXPERIMENTAL**
:param node_id: Id of the node to copy.
:param target_node_id: Id of the element to drop the copy into.
:param insert_before_node_id: *(Optional)* Drop the copy before this node (if absent, the copy becomes the last child of ```targetNodeId```).
:returns: Id of the node clone.
'''
params: T_JSON_DICT = dict()
params['nodeId'] = node_id.to_json()
params['targetNodeId'] = target_node_id.to_json()
if insert_before_node_id is not None:
params['insertBeforeNodeId'] = insert_before_node_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'DOM.copyTo',
'params': params,
}
json = yield cmd_dict
return NodeId.from_json(json['nodeId'])
def describe_node(
node_id: typing.Optional[NodeId] = None,
backend_node_id: typing.Optional[BackendNodeId] = None,
object_id: typing.Optional[runtime.RemoteObjectId] = None,
depth: typing.Optional[int] = None,
pierce: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,Node]:
r'''
Describes node given its id, does not require domain to be enabled. Does not start tracking any
objects, can be used for automation.
:param node_id: *(Optional)* Identifier of the node.
:param backend_node_id: *(Optional)* Identifier of the backend node.
:param object_id: *(Optional)* JavaScript object id of the node wrapper.
:param depth: *(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.
:param pierce: *(Optional)* Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
:returns: Node description.
'''
params: T_JSON_DICT = dict()
if node_id is not None:
params['nodeId'] = node_id.to_json()
if backend_node_id is not None:
params['backendNodeId'] = backend_node_id.to_json()
if object_id is not None:
params['objectId'] = object_id.to_json()
if depth is not None:
params['depth'] = depth
if pierce is not None:
params['pierce'] = pierce
cmd_dict: T_JSON_DICT = {
'method': 'DOM.describeNode',
'params': params,
}
json = yield cmd_dict
return Node.from_json(json['node'])
def scroll_into_view_if_needed(
node_id: typing.Optional[NodeId] = None,
backend_node_id: typing.Optional[BackendNodeId] = None,
object_id: typing.Optional[runtime.RemoteObjectId] = None,
rect: typing.Optional[Rect] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
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.
:param node_id: *(Optional)* Identifier of the node.
:param backend_node_id: *(Optional)* Identifier of the backend node.
:param object_id: *(Optional)* JavaScript object id of the node wrapper.
:param 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.
'''
params: T_JSON_DICT = dict()
if node_id is not None:
params['nodeId'] = node_id.to_json()
if backend_node_id is not None:
params['backendNodeId'] = backend_node_id.to_json()
if object_id is not None:
params['objectId'] = object_id.to_json()
if rect is not None:
params['rect'] = rect.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'DOM.scrollIntoViewIfNeeded',
'params': params,
}
json = yield cmd_dict
def disable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Disables DOM agent for the given page.
'''
cmd_dict: T_JSON_DICT = {
'method': 'DOM.disable',
}
json = yield cmd_dict
def discard_search_results(
search_id: str
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Discards search results from the session with the given id. ``getSearchResults`` should no longer
be called for that search.
**EXPERIMENTAL**
:param search_id: Unique search session identifier.
'''
params: T_JSON_DICT = dict()
params['searchId'] = search_id
cmd_dict: T_JSON_DICT = {
'method': 'DOM.discardSearchResults',
'params': params,
}
json = yield cmd_dict
def enable(
include_whitespace: typing.Optional[str] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Enables DOM agent for the given page.
:param include_whitespace: **(EXPERIMENTAL)** *(Optional)* Whether to include whitespaces in the children array of returned Nodes.
'''
params: T_JSON_DICT = dict()
if include_whitespace is not None:
params['includeWhitespace'] = include_whitespace
cmd_dict: T_JSON_DICT = {
'method': 'DOM.enable',
'params': params,
}
json = yield cmd_dict
def focus(
node_id: typing.Optional[NodeId] = None,
backend_node_id: typing.Optional[BackendNodeId] = None,
object_id: typing.Optional[runtime.RemoteObjectId] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Focuses the given element.
:param node_id: *(Optional)* Identifier of the node.
:param backend_node_id: *(Optional)* Identifier of the backend node.
:param object_id: *(Optional)* JavaScript object id of the node wrapper.
'''
params: T_JSON_DICT = dict()
if node_id is not None:
params['nodeId'] = node_id.to_json()
if backend_node_id is not None:
params['backendNodeId'] = backend_node_id.to_json()
if object_id is not None:
params['objectId'] = object_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'DOM.focus',
'params': params,
}
json = yield cmd_dict
def get_attributes(
node_id: NodeId
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[str]]:
r'''
Returns attributes for the specified node.
:param node_id: Id of the node to retrieve attributes for.
:returns: An interleaved array of node attribute names and values.
'''
params: T_JSON_DICT = dict()
params['nodeId'] = node_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'DOM.getAttributes',
'params': params,
}
json = yield cmd_dict
return [str(i) for i in json['attributes']]
def get_box_model(
node_id: typing.Optional[NodeId] = None,
backend_node_id: typing.Optional[BackendNodeId] = None,
object_id: typing.Optional[runtime.RemoteObjectId] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,BoxModel]:
r'''
Returns boxes for the given node.
:param node_id: *(Optional)* Identifier of the node.
:param backend_node_id: *(Optional)* Identifier of the backend node.
:param object_id: *(Optional)* JavaScript object id of the node wrapper.
:returns: Box model for the node.
'''
params: T_JSON_DICT = dict()
if node_id is not None:
params['nodeId'] = node_id.to_json()
if backend_node_id is not None:
params['backendNodeId'] = backend_node_id.to_json()
if object_id is not None:
params['objectId'] = object_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'DOM.getBoxModel',
'params': params,
}
json = yield cmd_dict
return BoxModel.from_json(json['model'])
def get_content_quads(
node_id: typing.Optional[NodeId] = None,
backend_node_id: typing.Optional[BackendNodeId] = None,
object_id: typing.Optional[runtime.RemoteObjectId] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[Quad]]:
r'''
Returns quads that describe node position on the page. This method
might return multiple quads for inline nodes.
**EXPERIMENTAL**
:param node_id: *(Optional)* Identifier of the node.
:param backend_node_id: *(Optional)* Identifier of the backend node.
:param object_id: *(Optional)* JavaScript object id of the node wrapper.
:returns: Quads that describe node layout relative to viewport.
'''
params: T_JSON_DICT = dict()
if node_id is not None:
params['nodeId'] = node_id.to_json()
if backend_node_id is not None:
params['backendNodeId'] = backend_node_id.to_json()
if object_id is not None:
params['objectId'] = object_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'DOM.getContentQuads',
'params': params,
}
json = yield cmd_dict
return [Quad.from_json(i) for i in json['quads']]
def get_document(
depth: typing.Optional[int] = None,
pierce: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,Node]:
r'''
Returns the root DOM node (and optionally the subtree) to the caller.
Implicitly enables the DOM domain events for the current target.
:param depth: *(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.
:param pierce: *(Optional)* Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
:returns: Resulting node.
'''
params: T_JSON_DICT = dict()
if depth is not None:
params['depth'] = depth
if pierce is not None:
params['pierce'] = pierce
cmd_dict: T_JSON_DICT = {
'method': 'DOM.getDocument',
'params': params,
}
json = yield cmd_dict
return Node.from_json(json['root'])
@deprecated(version="1.3")
def get_flattened_document(
depth: typing.Optional[int] = None,
pierce: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[Node]]:
r'''
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:: 1.3
:param depth: *(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.
:param pierce: *(Optional)* Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
:returns: Resulting node.
'''
params: T_JSON_DICT = dict()
if depth is not None:
params['depth'] = depth
if pierce is not None:
params['pierce'] = pierce
cmd_dict: T_JSON_DICT = {
'method': 'DOM.getFlattenedDocument',
'params': params,
}
json = yield cmd_dict
return [Node.from_json(i) for i in json['nodes']]
def get_nodes_for_subtree_by_style(
node_id: NodeId,
computed_styles: typing.List[CSSComputedStyleProperty],
pierce: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[NodeId]]:
r'''
Finds nodes with a given computed style in a subtree.
**EXPERIMENTAL**
:param node_id: Node ID pointing to the root of a subtree.
:param computed_styles: The style to filter nodes by (includes nodes if any of properties matches).
:param pierce: *(Optional)* Whether or not iframes and shadow roots in the same target should be traversed when returning the results (default is false).
:returns: Resulting nodes.
'''
params: T_JSON_DICT = dict()
params['nodeId'] = node_id.to_json()
params['computedStyles'] = [i.to_json() for i in computed_styles]
if pierce is not None: