-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathaccessibility.py
646 lines (543 loc) · 22.1 KB
/
accessibility.py
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
# 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: Accessibility (experimental)
from __future__ import annotations
from cdp.util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
from . import dom
from . import page
from . import runtime
class AXNodeId(str):
r'''
Unique accessibility node identifier.
'''
def to_json(self) -> str:
return self
@classmethod
def from_json(cls, json: str) -> AXNodeId:
return cls(json)
def __repr__(self):
return 'AXNodeId({})'.format(super().__repr__())
class AXValueType(enum.Enum):
r'''
Enum of possible property types.
'''
BOOLEAN = "boolean"
TRISTATE = "tristate"
BOOLEAN_OR_UNDEFINED = "booleanOrUndefined"
IDREF = "idref"
IDREF_LIST = "idrefList"
INTEGER = "integer"
NODE = "node"
NODE_LIST = "nodeList"
NUMBER = "number"
STRING = "string"
COMPUTED_STRING = "computedString"
TOKEN = "token"
TOKEN_LIST = "tokenList"
DOM_RELATION = "domRelation"
ROLE = "role"
INTERNAL_ROLE = "internalRole"
VALUE_UNDEFINED = "valueUndefined"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> AXValueType:
return cls(json)
class AXValueSourceType(enum.Enum):
r'''
Enum of possible property sources.
'''
ATTRIBUTE = "attribute"
IMPLICIT = "implicit"
STYLE = "style"
CONTENTS = "contents"
PLACEHOLDER = "placeholder"
RELATED_ELEMENT = "relatedElement"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> AXValueSourceType:
return cls(json)
class AXValueNativeSourceType(enum.Enum):
r'''
Enum of possible native property sources (as a subtype of a particular AXValueSourceType).
'''
DESCRIPTION = "description"
FIGCAPTION = "figcaption"
LABEL = "label"
LABELFOR = "labelfor"
LABELWRAPPED = "labelwrapped"
LEGEND = "legend"
RUBYANNOTATION = "rubyannotation"
TABLECAPTION = "tablecaption"
TITLE = "title"
OTHER = "other"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> AXValueNativeSourceType:
return cls(json)
@dataclass
class AXValueSource:
r'''
A single source for a computed AX property.
'''
#: What type of source this is.
type_: AXValueSourceType
#: The value of this property source.
value: typing.Optional[AXValue] = None
#: The name of the relevant attribute, if any.
attribute: typing.Optional[str] = None
#: The value of the relevant attribute, if any.
attribute_value: typing.Optional[AXValue] = None
#: Whether this source is superseded by a higher priority source.
superseded: typing.Optional[bool] = None
#: The native markup source for this value, e.g. a <label> element.
native_source: typing.Optional[AXValueNativeSourceType] = None
#: The value, such as a node or node list, of the native source.
native_source_value: typing.Optional[AXValue] = None
#: Whether the value for this property is invalid.
invalid: typing.Optional[bool] = None
#: Reason for the value being invalid, if it is.
invalid_reason: typing.Optional[str] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['type'] = self.type_.to_json()
if self.value is not None:
json['value'] = self.value.to_json()
if self.attribute is not None:
json['attribute'] = self.attribute
if self.attribute_value is not None:
json['attributeValue'] = self.attribute_value.to_json()
if self.superseded is not None:
json['superseded'] = self.superseded
if self.native_source is not None:
json['nativeSource'] = self.native_source.to_json()
if self.native_source_value is not None:
json['nativeSourceValue'] = self.native_source_value.to_json()
if self.invalid is not None:
json['invalid'] = self.invalid
if self.invalid_reason is not None:
json['invalidReason'] = self.invalid_reason
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> AXValueSource:
return cls(
type_=AXValueSourceType.from_json(json['type']),
value=AXValue.from_json(json['value']) if 'value' in json else None,
attribute=str(json['attribute']) if 'attribute' in json else None,
attribute_value=AXValue.from_json(json['attributeValue']) if 'attributeValue' in json else None,
superseded=bool(json['superseded']) if 'superseded' in json else None,
native_source=AXValueNativeSourceType.from_json(json['nativeSource']) if 'nativeSource' in json else None,
native_source_value=AXValue.from_json(json['nativeSourceValue']) if 'nativeSourceValue' in json else None,
invalid=bool(json['invalid']) if 'invalid' in json else None,
invalid_reason=str(json['invalidReason']) if 'invalidReason' in json else None,
)
@dataclass
class AXRelatedNode:
#: The BackendNodeId of the related DOM node.
backend_dom_node_id: dom.BackendNodeId
#: The IDRef value provided, if any.
idref: typing.Optional[str] = None
#: The text alternative of this node in the current context.
text: typing.Optional[str] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['backendDOMNodeId'] = self.backend_dom_node_id.to_json()
if self.idref is not None:
json['idref'] = self.idref
if self.text is not None:
json['text'] = self.text
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> AXRelatedNode:
return cls(
backend_dom_node_id=dom.BackendNodeId.from_json(json['backendDOMNodeId']),
idref=str(json['idref']) if 'idref' in json else None,
text=str(json['text']) if 'text' in json else None,
)
@dataclass
class AXProperty:
#: The name of this property.
name: AXPropertyName
#: The value of this property.
value: AXValue
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['name'] = self.name.to_json()
json['value'] = self.value.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> AXProperty:
return cls(
name=AXPropertyName.from_json(json['name']),
value=AXValue.from_json(json['value']),
)
@dataclass
class AXValue:
r'''
A single computed AX property.
'''
#: The type of this value.
type_: AXValueType
#: The computed value of this property.
value: typing.Optional[typing.Any] = None
#: One or more related nodes, if applicable.
related_nodes: typing.Optional[typing.List[AXRelatedNode]] = None
#: The sources which contributed to the computation of this property.
sources: typing.Optional[typing.List[AXValueSource]] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['type'] = self.type_.to_json()
if self.value is not None:
json['value'] = self.value
if self.related_nodes is not None:
json['relatedNodes'] = [i.to_json() for i in self.related_nodes]
if self.sources is not None:
json['sources'] = [i.to_json() for i in self.sources]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> AXValue:
return cls(
type_=AXValueType.from_json(json['type']),
value=json['value'] if 'value' in json else None,
related_nodes=[AXRelatedNode.from_json(i) for i in json['relatedNodes']] if 'relatedNodes' in json else None,
sources=[AXValueSource.from_json(i) for i in json['sources']] if 'sources' in json else None,
)
class AXPropertyName(enum.Enum):
r'''
Values of AXProperty name:
- from 'busy' to 'roledescription': states which apply to every AX node
- from 'live' to 'root': attributes which apply to nodes in live regions
- from 'autocomplete' to 'valuetext': attributes which apply to widgets
- from 'checked' to 'selected': states which apply to widgets
- from 'activedescendant' to 'owns' - relationships between elements other than parent/child/sibling.
'''
BUSY = "busy"
DISABLED = "disabled"
EDITABLE = "editable"
FOCUSABLE = "focusable"
FOCUSED = "focused"
HIDDEN = "hidden"
HIDDEN_ROOT = "hiddenRoot"
INVALID = "invalid"
KEYSHORTCUTS = "keyshortcuts"
SETTABLE = "settable"
ROLEDESCRIPTION = "roledescription"
LIVE = "live"
ATOMIC = "atomic"
RELEVANT = "relevant"
ROOT = "root"
AUTOCOMPLETE = "autocomplete"
HAS_POPUP = "hasPopup"
LEVEL = "level"
MULTISELECTABLE = "multiselectable"
ORIENTATION = "orientation"
MULTILINE = "multiline"
READONLY = "readonly"
REQUIRED = "required"
VALUEMIN = "valuemin"
VALUEMAX = "valuemax"
VALUETEXT = "valuetext"
CHECKED = "checked"
EXPANDED = "expanded"
MODAL = "modal"
PRESSED = "pressed"
SELECTED = "selected"
ACTIVEDESCENDANT = "activedescendant"
CONTROLS = "controls"
DESCRIBEDBY = "describedby"
DETAILS = "details"
ERRORMESSAGE = "errormessage"
FLOWTO = "flowto"
LABELLEDBY = "labelledby"
OWNS = "owns"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> AXPropertyName:
return cls(json)
@dataclass
class AXNode:
r'''
A node in the accessibility tree.
'''
#: Unique identifier for this node.
node_id: AXNodeId
#: Whether this node is ignored for accessibility
ignored: bool
#: Collection of reasons why this node is hidden.
ignored_reasons: typing.Optional[typing.List[AXProperty]] = None
#: This ``Node``'s role, whether explicit or implicit.
role: typing.Optional[AXValue] = None
#: The accessible name for this ``Node``.
name: typing.Optional[AXValue] = None
#: The accessible description for this ``Node``.
description: typing.Optional[AXValue] = None
#: The value for this ``Node``.
value: typing.Optional[AXValue] = None
#: All other properties
properties: typing.Optional[typing.List[AXProperty]] = None
#: ID for this node's parent.
parent_id: typing.Optional[AXNodeId] = None
#: IDs for each of this node's child nodes.
child_ids: typing.Optional[typing.List[AXNodeId]] = None
#: The backend ID for the associated DOM node, if any.
backend_dom_node_id: typing.Optional[dom.BackendNodeId] = None
#: The frame ID for the frame associated with this nodes document.
frame_id: typing.Optional[page.FrameId] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['nodeId'] = self.node_id.to_json()
json['ignored'] = self.ignored
if self.ignored_reasons is not None:
json['ignoredReasons'] = [i.to_json() for i in self.ignored_reasons]
if self.role is not None:
json['role'] = self.role.to_json()
if self.name is not None:
json['name'] = self.name.to_json()
if self.description is not None:
json['description'] = self.description.to_json()
if self.value is not None:
json['value'] = self.value.to_json()
if self.properties is not None:
json['properties'] = [i.to_json() for i in self.properties]
if self.parent_id is not None:
json['parentId'] = self.parent_id.to_json()
if self.child_ids is not None:
json['childIds'] = [i.to_json() for i in self.child_ids]
if self.backend_dom_node_id is not None:
json['backendDOMNodeId'] = self.backend_dom_node_id.to_json()
if self.frame_id is not None:
json['frameId'] = self.frame_id.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> AXNode:
return cls(
node_id=AXNodeId.from_json(json['nodeId']),
ignored=bool(json['ignored']),
ignored_reasons=[AXProperty.from_json(i) for i in json['ignoredReasons']] if 'ignoredReasons' in json else None,
role=AXValue.from_json(json['role']) if 'role' in json else None,
name=AXValue.from_json(json['name']) if 'name' in json else None,
description=AXValue.from_json(json['description']) if 'description' in json else None,
value=AXValue.from_json(json['value']) if 'value' in json else None,
properties=[AXProperty.from_json(i) for i in json['properties']] if 'properties' in json else None,
parent_id=AXNodeId.from_json(json['parentId']) if 'parentId' in json else None,
child_ids=[AXNodeId.from_json(i) for i in json['childIds']] if 'childIds' in json else None,
backend_dom_node_id=dom.BackendNodeId.from_json(json['backendDOMNodeId']) if 'backendDOMNodeId' in json else None,
frame_id=page.FrameId.from_json(json['frameId']) if 'frameId' in json else None,
)
def disable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Disables the accessibility domain.
'''
cmd_dict: T_JSON_DICT = {
'method': 'Accessibility.disable',
}
json = yield cmd_dict
def enable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Enables the accessibility domain which causes ``AXNodeId``'s to remain consistent between method calls.
This turns on accessibility for the page, which can impact performance until accessibility is disabled.
'''
cmd_dict: T_JSON_DICT = {
'method': 'Accessibility.enable',
}
json = yield cmd_dict
def get_partial_ax_tree(
node_id: typing.Optional[dom.NodeId] = None,
backend_node_id: typing.Optional[dom.BackendNodeId] = None,
object_id: typing.Optional[runtime.RemoteObjectId] = None,
fetch_relatives: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[AXNode]]:
r'''
Fetches the accessibility node and partial accessibility tree for this DOM node, if it exists.
**EXPERIMENTAL**
:param node_id: *(Optional)* Identifier of the node to get the partial accessibility tree for.
:param backend_node_id: *(Optional)* Identifier of the backend node to get the partial accessibility tree for.
:param object_id: *(Optional)* JavaScript object id of the node wrapper to get the partial accessibility tree for.
:param fetch_relatives: *(Optional)* Whether to fetch this nodes ancestors, siblings and children. Defaults to true.
:returns: The ``Accessibility.AXNode`` for this DOM node, if it exists, plus its ancestors, siblings and children, if requested.
'''
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 fetch_relatives is not None:
params['fetchRelatives'] = fetch_relatives
cmd_dict: T_JSON_DICT = {
'method': 'Accessibility.getPartialAXTree',
'params': params,
}
json = yield cmd_dict
return [AXNode.from_json(i) for i in json['nodes']]
def get_full_ax_tree(
depth: typing.Optional[int] = None,
max_depth: typing.Optional[int] = None,
frame_id: typing.Optional[page.FrameId] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[AXNode]]:
r'''
Fetches the entire accessibility tree for the root Document
**EXPERIMENTAL**
:param depth: *(Optional)* The maximum depth at which descendants of the root node should be retrieved. If omitted, the full tree is returned.
:param max_depth: **(DEPRECATED)** *(Optional)* Deprecated. This parameter has been renamed to ```depth```. If depth is not provided, max_depth will be used.
:param frame_id: *(Optional)* The frame for whose document the AX tree should be retrieved. If omited, the root frame is used.
:returns:
'''
params: T_JSON_DICT = dict()
if depth is not None:
params['depth'] = depth
if max_depth is not None:
params['max_depth'] = max_depth
if frame_id is not None:
params['frameId'] = frame_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Accessibility.getFullAXTree',
'params': params,
}
json = yield cmd_dict
return [AXNode.from_json(i) for i in json['nodes']]
def get_root_ax_node(
frame_id: typing.Optional[page.FrameId] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,AXNode]:
r'''
Fetches the root node.
Requires ``enable()`` to have been called previously.
**EXPERIMENTAL**
:param frame_id: *(Optional)* The frame in whose document the node resides. If omitted, the root frame is used.
:returns:
'''
params: T_JSON_DICT = dict()
if frame_id is not None:
params['frameId'] = frame_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Accessibility.getRootAXNode',
'params': params,
}
json = yield cmd_dict
return AXNode.from_json(json['node'])
def get_ax_node_and_ancestors(
node_id: typing.Optional[dom.NodeId] = None,
backend_node_id: typing.Optional[dom.BackendNodeId] = None,
object_id: typing.Optional[runtime.RemoteObjectId] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[AXNode]]:
r'''
Fetches a node and all ancestors up to and including the root.
Requires ``enable()`` to have been called previously.
**EXPERIMENTAL**
:param node_id: *(Optional)* Identifier of the node to get.
:param backend_node_id: *(Optional)* Identifier of the backend node to get.
:param object_id: *(Optional)* JavaScript object id of the node wrapper to get.
:returns:
'''
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': 'Accessibility.getAXNodeAndAncestors',
'params': params,
}
json = yield cmd_dict
return [AXNode.from_json(i) for i in json['nodes']]
def get_child_ax_nodes(
id_: AXNodeId,
frame_id: typing.Optional[page.FrameId] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[AXNode]]:
r'''
Fetches a particular accessibility node by AXNodeId.
Requires ``enable()`` to have been called previously.
**EXPERIMENTAL**
:param id_:
:param frame_id: *(Optional)* The frame in whose document the node resides. If omitted, the root frame is used.
:returns:
'''
params: T_JSON_DICT = dict()
params['id'] = id_.to_json()
if frame_id is not None:
params['frameId'] = frame_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Accessibility.getChildAXNodes',
'params': params,
}
json = yield cmd_dict
return [AXNode.from_json(i) for i in json['nodes']]
def query_ax_tree(
node_id: typing.Optional[dom.NodeId] = None,
backend_node_id: typing.Optional[dom.BackendNodeId] = None,
object_id: typing.Optional[runtime.RemoteObjectId] = None,
accessible_name: typing.Optional[str] = None,
role: typing.Optional[str] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[AXNode]]:
r'''
Query a DOM node's accessibility subtree for accessible name and role.
This command computes the name and role for all nodes in the subtree, including those that are
ignored for accessibility, and returns those that mactch the specified name and role. If no DOM
node is specified, or the DOM node does not exist, the command returns an error. If neither
``accessibleName`` or ``role`` is specified, it returns all the accessibility nodes in the subtree.
**EXPERIMENTAL**
:param node_id: *(Optional)* Identifier of the node for the root to query.
:param backend_node_id: *(Optional)* Identifier of the backend node for the root to query.
:param object_id: *(Optional)* JavaScript object id of the node wrapper for the root to query.
:param accessible_name: *(Optional)* Find nodes with this computed name.
:param role: *(Optional)* Find nodes with this computed role.
:returns: A list of ``Accessibility.AXNode`` matching the specified attributes, including nodes that are ignored for accessibility.
'''
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 accessible_name is not None:
params['accessibleName'] = accessible_name
if role is not None:
params['role'] = role
cmd_dict: T_JSON_DICT = {
'method': 'Accessibility.queryAXTree',
'params': params,
}
json = yield cmd_dict
return [AXNode.from_json(i) for i in json['nodes']]
@event_class('Accessibility.loadComplete')
@dataclass
class LoadComplete:
r'''
**EXPERIMENTAL**
The loadComplete event mirrors the load complete event sent by the browser to assistive
technology when the web page has finished loading.
'''
#: New document root node.
root: AXNode
@classmethod
def from_json(cls, json: T_JSON_DICT) -> LoadComplete:
return cls(
root=AXNode.from_json(json['root'])
)
@event_class('Accessibility.nodesUpdated')
@dataclass
class NodesUpdated:
r'''
**EXPERIMENTAL**
The nodesUpdated event is sent every time a previously requested node has changed the in tree.
'''
#: Updated node data.
nodes: typing.List[AXNode]
@classmethod
def from_json(cls, json: T_JSON_DICT) -> NodesUpdated:
return cls(
nodes=[AXNode.from_json(i) for i in json['nodes']]
)