1212import typing
1313
1414from . import dom
15+ from . import page
1516from . import runtime
1617
1718
@@ -83,11 +84,13 @@ class AXValueNativeSourceType(enum.Enum):
8384 '''
8485 Enum of possible native property sources (as a subtype of a particular AXValueSourceType).
8586 '''
87+ DESCRIPTION = "description"
8688 FIGCAPTION = "figcaption"
8789 LABEL = "label"
8890 LABELFOR = "labelfor"
8991 LABELWRAPPED = "labelwrapped"
9092 LEGEND = "legend"
93+ RUBYANNOTATION = "rubyannotation"
9194 TABLECAPTION = "tablecaption"
9295 TITLE = "title"
9396 OTHER = "other"
@@ -343,12 +346,18 @@ class AXNode:
343346 #: All other properties
344347 properties : typing .Optional [typing .List [AXProperty ]] = None
345348
349+ #: ID for this node's parent.
350+ parent_id : typing .Optional [AXNodeId ] = None
351+
346352 #: IDs for each of this node's child nodes.
347353 child_ids : typing .Optional [typing .List [AXNodeId ]] = None
348354
349355 #: The backend ID for the associated DOM node, if any.
350356 backend_dom_node_id : typing .Optional [dom .BackendNodeId ] = None
351357
358+ #: The frame ID for the frame associated with this nodes document.
359+ frame_id : typing .Optional [page .FrameId ] = None
360+
352361 def to_json (self ) -> T_JSON_DICT :
353362 json : T_JSON_DICT = dict ()
354363 json ['nodeId' ] = self .node_id .to_json ()
@@ -365,10 +374,14 @@ def to_json(self) -> T_JSON_DICT:
365374 json ['value' ] = self .value .to_json ()
366375 if self .properties is not None :
367376 json ['properties' ] = [i .to_json () for i in self .properties ]
377+ if self .parent_id is not None :
378+ json ['parentId' ] = self .parent_id .to_json ()
368379 if self .child_ids is not None :
369380 json ['childIds' ] = [i .to_json () for i in self .child_ids ]
370381 if self .backend_dom_node_id is not None :
371382 json ['backendDOMNodeId' ] = self .backend_dom_node_id .to_json ()
383+ if self .frame_id is not None :
384+ json ['frameId' ] = self .frame_id .to_json ()
372385 return json
373386
374387 @classmethod
@@ -382,8 +395,10 @@ def from_json(cls, json: T_JSON_DICT) -> AXNode:
382395 description = AXValue .from_json (json ['description' ]) if 'description' in json else None ,
383396 value = AXValue .from_json (json ['value' ]) if 'value' in json else None ,
384397 properties = [AXProperty .from_json (i ) for i in json ['properties' ]] if 'properties' in json else None ,
398+ parent_id = AXNodeId .from_json (json ['parentId' ]) if 'parentId' in json else None ,
385399 child_ids = [AXNodeId .from_json (i ) for i in json ['childIds' ]] if 'childIds' in json else None ,
386400 backend_dom_node_id = dom .BackendNodeId .from_json (json ['backendDOMNodeId' ]) if 'backendDOMNodeId' in json else None ,
401+ frame_id = page .FrameId .from_json (json ['frameId' ]) if 'frameId' in json else None ,
387402 )
388403
389404
@@ -442,16 +457,190 @@ def get_partial_ax_tree(
442457 return [AXNode .from_json (i ) for i in json ['nodes' ]]
443458
444459
445- def get_full_ax_tree () -> typing .Generator [T_JSON_DICT ,T_JSON_DICT ,typing .List [AXNode ]]:
460+ def get_full_ax_tree (
461+ depth : typing .Optional [int ] = None ,
462+ max_depth : typing .Optional [int ] = None ,
463+ frame_id : typing .Optional [page .FrameId ] = None
464+ ) -> typing .Generator [T_JSON_DICT ,T_JSON_DICT ,typing .List [AXNode ]]:
446465 '''
447- Fetches the entire accessibility tree
466+ Fetches the entire accessibility tree for the root Document
448467
449468 **EXPERIMENTAL**
450469
470+ :param depth: *(Optional)* The maximum depth at which descendants of the root node should be retrieved. If omitted, the full tree is returned.
471+ :param max_depth: **(DEPRECATED)** *(Optional)* Deprecated. This parameter has been renamed to ```depth```. If depth is not provided, max_depth will be used.
472+ :param frame_id: *(Optional)* The frame for whose document the AX tree should be retrieved. If omited, the root frame is used.
451473 :returns:
452474 '''
475+ params : T_JSON_DICT = dict ()
476+ if depth is not None :
477+ params ['depth' ] = depth
478+ if max_depth is not None :
479+ params ['max_depth' ] = max_depth
480+ if frame_id is not None :
481+ params ['frameId' ] = frame_id .to_json ()
453482 cmd_dict : T_JSON_DICT = {
454483 'method' : 'Accessibility.getFullAXTree' ,
484+ 'params' : params ,
455485 }
456486 json = yield cmd_dict
457487 return [AXNode .from_json (i ) for i in json ['nodes' ]]
488+
489+
490+ def get_root_ax_node (
491+ frame_id : typing .Optional [page .FrameId ] = None
492+ ) -> typing .Generator [T_JSON_DICT ,T_JSON_DICT ,AXNode ]:
493+ '''
494+ Fetches the root node.
495+ Requires ``enable()`` to have been called previously.
496+
497+ **EXPERIMENTAL**
498+
499+ :param frame_id: *(Optional)* The frame in whose document the node resides. If omitted, the root frame is used.
500+ :returns:
501+ '''
502+ params : T_JSON_DICT = dict ()
503+ if frame_id is not None :
504+ params ['frameId' ] = frame_id .to_json ()
505+ cmd_dict : T_JSON_DICT = {
506+ 'method' : 'Accessibility.getRootAXNode' ,
507+ 'params' : params ,
508+ }
509+ json = yield cmd_dict
510+ return AXNode .from_json (json ['node' ])
511+
512+
513+ def get_ax_node_and_ancestors (
514+ node_id : typing .Optional [dom .NodeId ] = None ,
515+ backend_node_id : typing .Optional [dom .BackendNodeId ] = None ,
516+ object_id : typing .Optional [runtime .RemoteObjectId ] = None
517+ ) -> typing .Generator [T_JSON_DICT ,T_JSON_DICT ,typing .List [AXNode ]]:
518+ '''
519+ Fetches a node and all ancestors up to and including the root.
520+ Requires ``enable()`` to have been called previously.
521+
522+ **EXPERIMENTAL**
523+
524+ :param node_id: *(Optional)* Identifier of the node to get.
525+ :param backend_node_id: *(Optional)* Identifier of the backend node to get.
526+ :param object_id: *(Optional)* JavaScript object id of the node wrapper to get.
527+ :returns:
528+ '''
529+ params : T_JSON_DICT = dict ()
530+ if node_id is not None :
531+ params ['nodeId' ] = node_id .to_json ()
532+ if backend_node_id is not None :
533+ params ['backendNodeId' ] = backend_node_id .to_json ()
534+ if object_id is not None :
535+ params ['objectId' ] = object_id .to_json ()
536+ cmd_dict : T_JSON_DICT = {
537+ 'method' : 'Accessibility.getAXNodeAndAncestors' ,
538+ 'params' : params ,
539+ }
540+ json = yield cmd_dict
541+ return [AXNode .from_json (i ) for i in json ['nodes' ]]
542+
543+
544+ def get_child_ax_nodes (
545+ id_ : AXNodeId ,
546+ frame_id : typing .Optional [page .FrameId ] = None
547+ ) -> typing .Generator [T_JSON_DICT ,T_JSON_DICT ,typing .List [AXNode ]]:
548+ '''
549+ Fetches a particular accessibility node by AXNodeId.
550+ Requires ``enable()`` to have been called previously.
551+
552+ **EXPERIMENTAL**
553+
554+ :param id_:
555+ :param frame_id: *(Optional)* The frame in whose document the node resides. If omitted, the root frame is used.
556+ :returns:
557+ '''
558+ params : T_JSON_DICT = dict ()
559+ params ['id' ] = id_ .to_json ()
560+ if frame_id is not None :
561+ params ['frameId' ] = frame_id .to_json ()
562+ cmd_dict : T_JSON_DICT = {
563+ 'method' : 'Accessibility.getChildAXNodes' ,
564+ 'params' : params ,
565+ }
566+ json = yield cmd_dict
567+ return [AXNode .from_json (i ) for i in json ['nodes' ]]
568+
569+
570+ def query_ax_tree (
571+ node_id : typing .Optional [dom .NodeId ] = None ,
572+ backend_node_id : typing .Optional [dom .BackendNodeId ] = None ,
573+ object_id : typing .Optional [runtime .RemoteObjectId ] = None ,
574+ accessible_name : typing .Optional [str ] = None ,
575+ role : typing .Optional [str ] = None
576+ ) -> typing .Generator [T_JSON_DICT ,T_JSON_DICT ,typing .List [AXNode ]]:
577+ '''
578+ Query a DOM node's accessibility subtree for accessible name and role.
579+ This command computes the name and role for all nodes in the subtree, including those that are
580+ ignored for accessibility, and returns those that mactch the specified name and role. If no DOM
581+ node is specified, or the DOM node does not exist, the command returns an error. If neither
582+ ``accessibleName`` or ``role`` is specified, it returns all the accessibility nodes in the subtree.
583+
584+ **EXPERIMENTAL**
585+
586+ :param node_id: *(Optional)* Identifier of the node for the root to query.
587+ :param backend_node_id: *(Optional)* Identifier of the backend node for the root to query.
588+ :param object_id: *(Optional)* JavaScript object id of the node wrapper for the root to query.
589+ :param accessible_name: *(Optional)* Find nodes with this computed name.
590+ :param role: *(Optional)* Find nodes with this computed role.
591+ :returns: A list of ``Accessibility.AXNode`` matching the specified attributes, including nodes that are ignored for accessibility.
592+ '''
593+ params : T_JSON_DICT = dict ()
594+ if node_id is not None :
595+ params ['nodeId' ] = node_id .to_json ()
596+ if backend_node_id is not None :
597+ params ['backendNodeId' ] = backend_node_id .to_json ()
598+ if object_id is not None :
599+ params ['objectId' ] = object_id .to_json ()
600+ if accessible_name is not None :
601+ params ['accessibleName' ] = accessible_name
602+ if role is not None :
603+ params ['role' ] = role
604+ cmd_dict : T_JSON_DICT = {
605+ 'method' : 'Accessibility.queryAXTree' ,
606+ 'params' : params ,
607+ }
608+ json = yield cmd_dict
609+ return [AXNode .from_json (i ) for i in json ['nodes' ]]
610+
611+
612+ @event_class ('Accessibility.loadComplete' )
613+ @dataclass
614+ class LoadComplete :
615+ '''
616+ **EXPERIMENTAL**
617+
618+ The loadComplete event mirrors the load complete event sent by the browser to assistive
619+ technology when the web page has finished loading.
620+ '''
621+ #: New document root node.
622+ root : AXNode
623+
624+ @classmethod
625+ def from_json (cls , json : T_JSON_DICT ) -> LoadComplete :
626+ return cls (
627+ root = AXNode .from_json (json ['root' ])
628+ )
629+
630+
631+ @event_class ('Accessibility.nodesUpdated' )
632+ @dataclass
633+ class NodesUpdated :
634+ '''
635+ **EXPERIMENTAL**
636+
637+ The nodesUpdated event is sent every time a previously requested node has changed the in tree.
638+ '''
639+ #: Updated node data.
640+ nodes : typing .List [AXNode ]
641+
642+ @classmethod
643+ def from_json (cls , json : T_JSON_DICT ) -> NodesUpdated :
644+ return cls (
645+ nodes = [AXNode .from_json (i ) for i in json ['nodes' ]]
646+ )
0 commit comments