1# AccessibilityExtensionContext (Accessibility Extension Context)
2
3The **AccessibilityExtensionContext** module, inherited from **ExtensionContext**, provides context for **AccessibilityExtensionAbility**.
4
5You can use the APIs of this module to configure the concerned information, obtain root information, and inject gestures.
6
7> **NOTE**
8>
9> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
10
11## Usage
12
13Before using the **AccessibilityExtensionContext** module, you must define a child class that inherits from **AccessibilityExtensionAbility**.
14
15```ts
16import { AccessibilityExtensionAbility } from '@kit.AccessibilityKit';
17
18class EntryAbility extends AccessibilityExtensionAbility {
19  onConnect(): void {
20    let axContext = this.context;
21  }
22}
23```
24
25## ElementAttributeValues
26
27Provides attribute names and value types of a node element.
28
29**System capability**: SystemCapability.BarrierFree.Accessibility.Core
30
31### Name
32
33| Name                  | Type                                                                | Readable | Writable | Description                 |
34|----------------------|--------------------------------------------------------------------|-----|-----| ------------------- |
35| accessibilityFocused | boolean                                                            | Yes  | No  |   Accessibility focus status.  |
36| accessibilityText<sup>12+</sup> | string                                                  | Yes  | No  | Accessibility text information of an element.|
37| bundleName           | string                                                             | Yes  | No  | Bundle name.|
38| checkable            | boolean                                                            | Yes  | No  | Whether the element is checkable.|
39| checked              | boolean                                                            | Yes  | No  | Whether the element is checked.|
40| children             | Array&lt;[AccessibilityElement](#accessibilityelement9)&gt;        | Yes  | No  | All child elements.|
41| clickable            | boolean                                                            | Yes  | No  | Whether the element is clickable.|
42| componentId          | number                                                             | Yes  | No  | ID of the component to which the element belongs.|
43| componentType        | string                                                             | Yes  | No  | Type of the component to which the element belongs.|
44| contents             | Array&lt;string&gt;                                                | Yes  | No  | Content.|
45| currentIndex         | number                                                             | Yes  | No  | Index of the current item.|
46| description          | string                                                             | Yes  | No  | Description of the element.|
47| editable             | boolean                                                            | Yes  | No  | Whether the element is editable.|
48| endIndex             | number                                                             | Yes  | No  | Index of the last list item displayed on the screen.|
49| error                | string                                                             | Yes  | No  | Error status.|
50| focusable            | boolean                                                            | Yes  | No  | Whether the element is focusable.|
51| hintText             | string                                                             | Yes  | No  | Hint text.|
52| inputType            | number                                                             | Yes  | No  | Type of the input text.|
53| inspectorKey         | string                                                             | Yes  | No  | Inspector key.|
54| isActive             | boolean                                                            | Yes  | No  | Whether the element is active.|
55| isEnable             | boolean                                                            | Yes  | No  | Whether the element is enabled.|
56| isHint               | boolean                                                            | Yes  | No  | Whether the element is in the hint state.|
57| isFocused            | boolean                                                            | Yes  | No  | Whether the element is focused.|
58| isPassword           | boolean                                                            | Yes  | No  | Whether the element is a password.|
59| isVisible            | boolean                                                            | Yes  | No  | Whether the element is visible.|
60| itemCount            | number                                                             | Yes  | No  | Total number of items.|
61| lastContent          | string                                                             | Yes  | No  | Last content.|
62| layer                | number                                                             | Yes  | No  | Display layer of the element.|
63| longClickable        | boolean                                                            | Yes  | No  | Whether the element is long-clickable.|
64| pageId               | number                                                             | Yes  | No  | Page ID.|
65| parent               | [AccessibilityElement](#accessibilityelement9)                     | Yes  | No  | Parent element of the element.|
66| pluralLineSupported  | boolean                                                            | Yes  | No  | Whether the element supports multiple lines of text.|
67| rect                 | [Rect](#rect)                                                      | Yes  | No  | Area of the element.|
68| resourceName         | string                                                             | Yes  | No  | Resource name of the element.|
69| rootElement          | [AccessibilityElement](#accessibilityelement9)                     | Yes  | No  | Root element of the window element.|
70| screenRect           | [Rect](#rect)                                                      | Yes  | No  | Display area of the element.|
71| scrollable           | boolean                                                            | Yes  | No  | Whether the element is scrollable.|
72| selected             | boolean                                                            | Yes  | No  | Whether the element is selected.|
73| startIndex           | number                                                             | Yes  | No  | Index of the first list item on the screen.|
74| text                 | string                                                             | Yes  | No  | Text of the element.|
75| textLengthLimit      | number                                                             | Yes  | No  | Maximum text length of the element.|
76| textMoveUnit         | [accessibility.TextMoveUnit](js-apis-accessibility.md#textmoveunit) | Yes  | No  | Unit of movement when the text is read.|
77| triggerAction        | [accessibility.Action](js-apis-accessibility.md#action)         | Yes  | No  | Action that triggers the element event.|
78| type                 | [WindowType](#windowtype)                                          | Yes  | No  | Window type of the element.|
79| valueMax             | number                                                             | Yes  | No  | Maximum value.|
80| valueMin             | number                                                             | Yes  | No  | Minimum value.|
81| valueNow             | number                                                             | Yes  | No  | Current value.|
82| windowId             | number                                                             | Yes  | No  | Window ID.|
83| textType<sup>12+</sup>             | string                                                             | Yes  | No  | Accessibility text type of an element, which is configured by the **accessibilityTextHint** attribute of the component.|
84| offset<sup>12+</sup>             | number                                                             | Yes  | No  | Pixel offset of the content area relative to the top coordinate of a scrollable component, such as **List** and **Grid**.|
85| hotArea<sup>12+</sup>             | [Rect](#rect)                                                              | Yes  | No  | Touchable area of an element.|
86
87## FocusDirection
88
89type FocusDirection = 'up' | 'down' | 'left' | 'right' | 'forward' | 'backward'
90
91Enumerates the focus directions.
92
93**System capability**: SystemCapability.BarrierFree.Accessibility.Core
94
95| Type      | Description     |
96| -------- | ------- |
97| 'up'       | Search for the next focusable item above the current item in focus.|
98| 'down'     | Search for the next focusable item below the current item in focus.|
99| 'left'     | Search for the next focusable item on the left of the current item in focus.|
100| 'right'    | Search for the next focusable item on the right of the current item in focus.|
101| 'forward'  | Search for the next focusable item before the current item in focus.|
102| 'backward' | Search for the next focusable item after the current item in focus.|
103
104## FocusType
105
106type FocusType = 'accessibility' | 'normal'
107
108Enumerates the focus types.
109
110**System capability**: SystemCapability.BarrierFree.Accessibility.Core
111
112| Type           | Description         |
113| ------------- | ----------- |
114| 'accessibility' | Accessibility focus.|
115| 'normal'        | Normal focus. |
116
117## Rect
118
119Defines a rectangle.
120
121**System capability**: SystemCapability.BarrierFree.Accessibility.Core
122
123| Name    | Type    | Readable  | Writable  | Description       |
124| ------ | ------ | ---- | ---- | --------- |
125| left   | number | Yes   | No   | Left boundary of the rectangle.|
126| top    | number | Yes   | No   | Top boundary of the rectangle.|
127| width  | number | Yes   | No   | Width of the rectangle. |
128| height | number | Yes   | No   | Height of the rectangle. |
129
130## WindowType
131
132type WindowType = 'application' | 'system'
133
134Enumerates the window types.
135
136**System capability**: SystemCapability.BarrierFree.Accessibility.Core
137
138| Type         | Description       |
139| ----------- | --------- |
140| 'application' | Application window.|
141| 'system'      | System window.|
142
143## AccessibilityExtensionContext.setTargetBundleName<sup>(deprecated)</sup>
144
145setTargetBundleName(targetNames: Array\<string>): Promise\<void>;
146
147Sets the concerned target bundle. This API uses a promise to return the result.
148
149> **NOTE**
150>
151> This API is deprecated since API version 12.
152
153**System capability**: SystemCapability.BarrierFree.Accessibility.Core
154
155**Parameters**
156
157| Name        | Type                 | Mandatory  | Description      |
158| ----------- | ------------------- | ---- | -------- |
159| targetNames | Array&lt;string&gt; | Yes   | Bundle name of the concerned target application. The service receives accessibility events of the concerned application. By default, accessibility events of all applications are received. Pass in an empty array if there is no concerned application.|
160
161**Return value**
162
163| Type                 | Description              |
164| ------------------- | ---------------- |
165| Promise&lt;void&gt; | Promise that returns no value.|
166
167**Error codes**
168
169For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
170
171| ID| Error Message|
172| ------- | -------------------------------- |
173| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
174
175**Example**
176
177```ts
178import { BusinessError } from '@kit.BasicServicesKit';
179
180let targetNames = ['com.ohos.xyz'];
181axContext.setTargetBundleName(targetNames).then(() => {
182  console.info(`Succeeded in set target bundle names, targetNames is ${targetNames}`);
183}).catch((err: BusinessError) => {
184  console.error(`failed to set target bundle names, Code is ${err.code}, message is ${err.message}`);
185})
186```
187
188## AccessibilityExtensionContext.setTargetBundleName<sup>(deprecated)</sup>
189
190setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>): void;
191
192Sets the concerned target bundle. This API uses an asynchronous callback to return the result.
193
194> **NOTE**
195>
196> This API is deprecated since API version 12.
197
198**System capability**: SystemCapability.BarrierFree.Accessibility.Core
199
200**Parameters**
201
202| Name        | Type                       | Mandatory  | Description                                      |
203| ----------- | ------------------------- | ---- | ---------------------------------------- |
204| targetNames | Array&lt;string&gt;       | Yes   | Bundle name of the concerned target application. The service receives accessibility events of the concerned application. By default, accessibility events of all applications are received. Pass in an empty array if there is no concerned application.                                |
205| callback    | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result. If the operation fails, **err** that contains data is returned.|
206
207**Error codes**
208
209For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
210
211| ID| Error Message|
212| ------- | -------------------------------- |
213| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
214
215**Example**
216
217```ts
218import { BusinessError } from '@kit.BasicServicesKit';
219
220let targetNames = ['com.ohos.xyz'];
221try {
222  axContext.setTargetBundleName(targetNames, (err: BusinessError) => {
223    if (err && err.code) {
224      console.error(`failed to set target bundle names, Code is ${err.code}, message is ${err.message}`);
225      return;
226    }
227    console.info(`Succeeded in set target bundle names, targetNames is ${targetNames}`);
228  });
229} catch (error) {
230  console.error(`failed to set target bundle names, Because ${JSON.stringify(error)}`);
231}
232```
233
234## AccessibilityExtensionContext.getFocusElement<sup>(deprecated)</sup>
235
236getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>;
237
238Obtains the focus element. This API uses a promise to return the result.
239
240> **NOTE**
241>
242> This API is deprecated since API version 12.
243
244**System capability**: SystemCapability.BarrierFree.Accessibility.Core
245
246**Parameters**
247
248| Name                 | Type     | Mandatory  | Description                 |
249| -------------------- | ------- | ---- | ------------------- |
250| isAccessibilityFocus | boolean | No   | Whether the obtained focus element is an accessibility focus. The value **True** means that the obtained focus element is an accessibility focus, and **False** means the opposite. The default value is **False**.|
251
252**Return value**
253| Type                                 | Description                    |
254| ----------------------------------- | ---------------------- |
255| Promise&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Promise used to return the current focus element.|
256
257**Error codes**
258
259For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
260
261| ID  | Error Message                                    |
262| ------- | ---------------------------------------- |
263| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
264| 9300003 | No accessibility permission to perform the operation. |
265
266**Example**
267
268```ts
269import { AccessibilityElement } from '@kit.AccessibilityKit';
270import { BusinessError } from '@kit.BasicServicesKit';
271
272let rootElement: AccessibilityElement;
273
274axContext.getFocusElement().then((data: AccessibilityElement) => {
275  rootElement = data;
276  console.log(`Succeeded in get focus element,${JSON.stringify(data)}`);
277}).catch((err: BusinessError) => {
278  console.error(`failed to get focus element, Code is ${err.code}, message is ${err.message}`);
279})
280```
281
282## AccessibilityExtensionContext.getFocusElement<sup>(deprecated)</sup>
283
284getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void;
285
286Obtains the focus element. This API uses an asynchronous callback to return the result.
287
288> **NOTE**
289>
290> This API is deprecated since API version 12.
291
292**System capability**: SystemCapability.BarrierFree.Accessibility.Core
293
294**Parameters**
295
296| Name     | Type                                      | Mandatory  | Description               |
297| -------- | ---------------------------------------- | ---- | ----------------- |
298| callback | AsyncCallback&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Yes   | Callback used to return the current focus element.|
299
300**Error codes**
301
302For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
303
304| ID  | Error Message                                    |
305| ------- | ---------------------------------------- |
306| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
307| 9300003 | No accessibility permission to perform the operation. |
308
309**Example**
310
311```ts
312import { AccessibilityElement } from '@kit.AccessibilityKit';
313import { BusinessError } from '@kit.BasicServicesKit';
314
315let rootElement: AccessibilityElement;
316
317axContext.getFocusElement((err: BusinessError, data: AccessibilityElement) => {
318  if (err && err.code) {
319    console.error(`failed to get focus element, Code is ${err.code}, message is ${err.message}`);
320    return;
321  }
322  rootElement = data;
323  console.info(`Succeeded in get focus element, ${JSON.stringify(data)}`);
324});
325```
326
327## AccessibilityExtensionContext.getFocusElement<sup>(deprecated)</sup>
328
329getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<AccessibilityElement>): void;
330
331Obtains the focus element. This API uses an asynchronous callback to return the result.
332
333> **NOTE**
334>
335> This API is deprecated since API version 12.
336
337**System capability**: SystemCapability.BarrierFree.Accessibility.Core
338
339**Parameters**
340
341| Name                 | Type                                      | Mandatory  | Description               |
342| -------------------- | ---------------------------------------- | ---- | ----------------- |
343| isAccessibilityFocus | boolean                                  | Yes   | Whether the obtained focus element is an accessibility focus. The value **True** means that the obtained focus element is an accessibility focus, and **False** means the opposite.   |
344| callback             | AsyncCallback&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Yes   | Callback used to return the current focus element.|
345
346**Error codes**
347
348For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
349
350| ID  | Error Message                                    |
351| ------- | ---------------------------------------- |
352| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
353| 9300003 | No accessibility permission to perform the operation. |
354
355**Example**
356
357```ts
358import { AccessibilityElement } from '@kit.AccessibilityKit';
359import { BusinessError } from '@kit.BasicServicesKit';
360
361let isAccessibilityFocus = true;
362let rootElement: AccessibilityElement;
363
364axContext.getFocusElement(isAccessibilityFocus, (err: BusinessError, data: AccessibilityElement)=> {
365  if (err && err.code) {
366    console.error(`failed to get focus element, Code is ${err.code}, message is ${err.message}`);
367    return;
368  }
369  rootElement = data;
370  console.info(`Succeeded in get focus element, ${JSON.stringify(data)}`);
371});
372```
373
374## AccessibilityExtensionContext.getWindowRootElement<sup>(deprecated)</sup>
375
376getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>;
377
378Obtains the root element of a window. This API uses a promise to return the result.
379
380> **NOTE**
381>
382> This API is deprecated since API version 12.
383
384**System capability**: SystemCapability.BarrierFree.Accessibility.Core
385
386**Parameters**
387
388| Name     | Type    | Mandatory  | Description                    |
389| -------- | ------ | ---- | ---------------------- |
390| windowId | number | No   | Window for which you want to obtain the root element. If this parameter is not specified, it indicates the current active window.|
391
392**Return value**
393
394| Type                                 | Description                    |
395| ----------------------------------- | ---------------------- |
396| Promise&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Promise used to return the root element of the specified window.|
397
398**Error codes**
399
400For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
401
402| ID  | Error Message                                    |
403| ------- | ---------------------------------------- |
404| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
405| 9300003 | No accessibility permission to perform the operation. |
406
407**Example**
408
409```ts
410import { AccessibilityElement } from '@kit.AccessibilityKit';
411import { BusinessError } from '@kit.BasicServicesKit';
412
413let rootElement: AccessibilityElement;
414
415axContext.getWindowRootElement().then((data: AccessibilityElement) => {
416  rootElement = data;
417  console.log(`Succeeded in get root element of the window, ${JSON.stringify(data)}`);
418}).catch((err: BusinessError) => {
419  console.error(`failed to get root element of the window, Code is ${err.code}, message is ${err.message}`);
420});
421```
422
423## AccessibilityExtensionContext.getWindowRootElement<sup>(deprecated)</sup>
424
425getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void;
426
427Obtains the root element of a window. This API uses an asynchronous callback to return the result.
428
429> **NOTE**
430>
431> This API is deprecated since API version 12.
432
433**System capability**: SystemCapability.BarrierFree.Accessibility.Core
434
435**Parameters**
436
437| Name     | Type                                      | Mandatory  | Description                |
438| -------- | ---------------------------------------- | ---- | ------------------ |
439| callback | AsyncCallback&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Yes   | Callback used to return the root element.|
440
441**Error codes**
442
443For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
444
445| ID  | Error Message                                    |
446| ------- | ---------------------------------------- |
447| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
448| 9300003 | No accessibility permission to perform the operation. |
449
450**Example**
451
452```ts
453import { AccessibilityElement } from '@kit.AccessibilityKit';
454import { BusinessError } from '@kit.BasicServicesKit';
455
456let rootElement: AccessibilityElement;
457
458axContext.getWindowRootElement((err: BusinessError, data: AccessibilityElement) => {
459  if (err && err.code) {
460    console.error(`failed to get root element of the window, Code is ${err.code}, message is ${err.message}`);
461    return;
462  }
463  rootElement = data;
464  console.info(`Succeeded in get root element of the window, ${JSON.stringify(data)}`);
465});
466```
467
468## AccessibilityExtensionContext.getWindowRootElement<sup>(deprecated)</sup>
469
470getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityElement>): void;
471
472Obtains the root element of a window. This API uses an asynchronous callback to return the result.
473
474> **NOTE**
475>
476> This API is deprecated since API version 12.
477
478**System capability**: SystemCapability.BarrierFree.Accessibility.Core
479
480**Parameters**
481
482| Name     | Type                                      | Mandatory  | Description                    |
483| -------- | ---------------------------------------- | ---- | ---------------------- |
484| windowId | number                                   | Yes   | Window for which you want to obtain the root element. If this parameter is not specified, it indicates the current active window.|
485| callback | AsyncCallback&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Yes   | Callback used to return the root element.    |
486
487**Error codes**
488
489For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
490
491| ID  | Error Message                                    |
492| ------- | ---------------------------------------- |
493| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
494| 9300003 | No accessibility permission to perform the operation. |
495
496**Example**
497
498```ts
499import { AccessibilityElement } from '@kit.AccessibilityKit';
500import { BusinessError } from '@kit.BasicServicesKit';
501
502let windowId = 10;
503let rootElement: AccessibilityElement;
504
505axContext.getWindowRootElement(windowId, (err: BusinessError, data: AccessibilityElement) => {
506  if (err && err.code) {
507    console.error(`failed to get root element of the window, Code is ${err.code}, message is ${err.message}`);
508    return;
509  }
510  rootElement = data;
511  console.info(`Succeeded in get root element of the window, ${JSON.stringify(data)}`);
512});
513```
514
515## AccessibilityExtensionContext.getWindows<sup>(deprecated)</sup>
516
517getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>;
518
519Obtains the list of windows on a display. This API uses a promise to return the result.
520
521> **NOTE**
522>
523> This API is deprecated since API version 12.
524
525**System capability**: SystemCapability.BarrierFree.Accessibility.Core
526
527**Parameters**
528
529| Name      | Type    | Mandatory  | Description                   |
530| --------- | ------ | ---- | --------------------- |
531| displayId | number | No   | ID of the display from which the window information is obtained. If this parameter is not specified, it indicates the default main display.|
532
533**Return value**
534
535| Type                                      | Description                    |
536| ---------------------------------------- | ---------------------- |
537| Promise&lt;Array&lt;[AccessibilityElement](#accessibilityelement9)&gt;&gt; | Promise used to return the window list.|
538
539**Error codes**
540
541For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
542
543| ID  | Error Message                                    |
544| ------- | ---------------------------------------- |
545| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
546| 9300003 | No accessibility permission to perform the operation. |
547
548**Example**
549
550```ts
551import { AccessibilityElement } from '@kit.AccessibilityKit';
552import { BusinessError } from '@kit.BasicServicesKit';
553
554axContext.getWindows().then((data: AccessibilityElement[]) => {
555  console.log(`Succeeded in get windows, ${JSON.stringify(data)}`);
556}).catch((err: BusinessError) => {
557  console.error(`failed to get windows, Code is ${err.code}, message is ${err.message}`);
558});
559```
560
561## AccessibilityExtensionContext.getWindows<sup>(deprecated)</sup>
562
563getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void;
564
565Obtains the list of windows on this display. This API uses an asynchronous callback to return the result.
566
567> **NOTE**
568>
569> This API is deprecated since API version 12.
570
571**System capability**: SystemCapability.BarrierFree.Accessibility.Core
572
573**Parameters**
574
575| Name     | Type                                      | Mandatory  | Description               |
576| -------- | ---------------------------------------- | ---- | ----------------- |
577| callback | AsyncCallback&lt;Array&lt;[AccessibilityElement](#accessibilityelement9)&gt;&gt; | Yes   | Callback used to return the window list.|
578
579**Error codes**
580
581For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
582
583| ID  | Error Message                                    |
584| ------- | ---------------------------------------- |
585| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
586| 9300003 | No accessibility permission to perform the operation. |
587
588**Example**
589
590```ts
591import { AccessibilityElement } from '@kit.AccessibilityKit';
592import { BusinessError } from '@kit.BasicServicesKit';
593
594axContext.getWindows((err: BusinessError, data: AccessibilityElement[]) => {
595  if (err && err.code) {
596    console.error(`failed to get windows, Code is ${err.code}, message is ${err.message}`);
597    return;
598  }
599  console.info(`Succeeded in get windows, ${JSON.stringify(data)}`);
600});
601```
602
603## AccessibilityExtensionContext.getWindows<sup>(deprecated)</sup>
604
605getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityElement>>): void;
606
607Obtains the list of windows on this display. This API uses an asynchronous callback to return the result.
608
609> **NOTE**
610>
611> This API is deprecated since API version 12.
612
613**System capability**: SystemCapability.BarrierFree.Accessibility.Core
614
615**Parameters**
616
617| Name      | Type                                      | Mandatory  | Description                   |
618| --------- | ---------------------------------------- | ---- | --------------------- |
619| displayId | number                                   | Yes   | ID of the display from which the window information is obtained. If this parameter is not specified, it indicates the default main display.|
620| callback  | AsyncCallback&lt;Array&lt;[AccessibilityElement](#accessibilityelement9)&gt;&gt; | Yes   | Callback used to return the window list.    |
621
622**Error codes**
623
624For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
625
626| ID  | Error Message                                    |
627| ------- | ---------------------------------------- |
628| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
629| 9300003 | No accessibility permission to perform the operation. |
630
631**Example**
632
633```ts
634import { AccessibilityElement } from '@kit.AccessibilityKit';
635import { BusinessError } from '@kit.BasicServicesKit';
636
637let displayId = 10;
638axContext.getWindows(displayId, (err: BusinessError, data: AccessibilityElement[]) => {
639  if (err && err.code) {
640    console.error(`failed to get windows, Code is ${err.code}, message is ${err.message}`);
641    return;
642  }
643  console.info(`Succeeded in get windows, ${JSON.stringify(data)}`);
644});
645```
646
647## AccessibilityExtensionContext.injectGesture<sup>(deprecated)</sup>
648
649injectGesture(gesturePath: GesturePath): Promise\<void>;
650
651> **NOTE**
652>
653> This API is deprecated since API version 10.
654
655Injects a gesture. This API uses a promise to return the result.
656
657**System capability**: SystemCapability.BarrierFree.Accessibility.Core
658
659**Parameters**
660
661| Name        | Type                                                                | Mandatory  | Description        |
662| ----------- |--------------------------------------------------------------------| ---- | ---------- |
663| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | Yes   | Path of the gesture to inject.|
664
665**Return value**
666
667| Type                 | Description              |
668| ------------------- | ---------------- |
669| Promise&lt;void&gt; | Promise that returns no value.|
670
671**Error codes**
672
673For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
674
675| ID  | Error Message                                    |
676| ------- | ---------------------------------------- |
677| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
678| 9300003 | No accessibility permission to perform the operation. |
679
680**Example**
681
682```ts
683import { GesturePath, GesturePoint } from '@kit.AccessibilityKit';
684import { BusinessError } from '@kit.BasicServicesKit';
685
686let gesturePath: GesturePath = new GesturePath(100);
687
688for (let i = 0; i < 10; i++) {
689  let gesturePoint = new GesturePoint(100, i * 200);
690  gesturePath.points.push(gesturePoint);
691}
692axContext.injectGesture(gesturePath).then(() => {
693  console.info(`Succeeded in inject gesture,gesturePath is ${gesturePath}`);
694}).catch((err: BusinessError) => {
695  console.error(`failed to inject gesture, Code is ${err.code}, message is ${err.message}`);
696});
697```
698## AccessibilityExtensionContext.injectGesture<sup>(deprecated)</sup>
699
700injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void
701
702> **NOTE**
703>
704> This API is deprecated since API version 10.
705
706Injects a gesture. This API uses an asynchronous callback to return the result.
707
708**System capability**: SystemCapability.BarrierFree.Accessibility.Core
709
710**Parameters**
711
712| Name        | Type                                                                | Mandatory  | Description                 |
713| ----------- |--------------------------------------------------------------------| ---- | ------------------- |
714| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | Yes   | Path of the gesture to inject.         |
715| callback    | AsyncCallback&lt;void&gt;                                          | Yes   | Callback used to return the result.|
716
717**Error codes**
718
719For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
720
721| ID  | Error Message                                    |
722| ------- | ---------------------------------------- |
723| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
724| 9300003 | No accessibility permission to perform the operation. |
725
726**Example**
727
728```ts
729import { GesturePath, GesturePoint } from '@kit.AccessibilityKit';
730import { BusinessError } from '@kit.BasicServicesKit';
731
732let gesturePath: GesturePath = new GesturePath(100);
733for (let i = 0; i < 10; i++) {
734  let gesturePoint = new GesturePoint(100, i * 200);
735  gesturePath.points.push(gesturePoint);
736}
737axContext.injectGesture(gesturePath, (err: BusinessError) => {
738  if (err) {
739    console.error(`failed to inject gesture, Code is ${err.code}, message is ${err.message}`);
740    return;
741  }
742  console.info(`Succeeded in inject gesture,gesturePath is ${gesturePath}`);
743});
744```
745## AccessibilityExtensionContext.injectGestureSync<sup>(deprecated)</sup>
746
747injectGestureSync(gesturePath: GesturePath): void
748
749Injects a gesture.
750
751> **NOTE**
752>
753> This API is deprecated since API version 12.
754
755**System capability**: SystemCapability.BarrierFree.Accessibility.Core
756
757**Parameters**
758
759| Name     | Type                                                                | Mandatory| Description                |
760| ----------- |--------------------------------------------------------------------| ---- | -------------------- |
761| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | Yes  | Path of the gesture to inject.|
762
763**Error codes**
764
765For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
766
767| ID| Error Message                                           |
768| -------- | --------------------------------------------------- |
769| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
770| 9300003  | No accessibility permission to perform the operation. |
771
772**Example**
773
774```ts
775import { GesturePath, GesturePoint } from '@kit.AccessibilityKit';
776
777let gesturePath: GesturePath = new GesturePath(100);
778for (let i = 0; i < 10; i++) {
779  let gesturePoint = new GesturePoint(100, i * 200);
780  gesturePath.points.push(gesturePoint);
781}
782axContext.injectGestureSync(gesturePath);
783```
784
785## AccessibilityElement<sup>9+</sup>
786
787Defines the **AccessibilityElement**. Before calling APIs of **AccessibilityElement**, you must call [AccessibilityExtensionContext.getFocusElement()](#accessibilityextensioncontextgetfocuselementdeprecated) or [AccessibilityExtensionContext.getWindowRootElement()](#accessibilityextensioncontextgetwindowrootelementdeprecated) to obtain an **AccessibilityElement** instance.
788
789**System capability**: SystemCapability.BarrierFree.Accessibility.Core
790
791### attributeNames<sup>(deprecated)</sup>
792
793attributeNames\<T extends keyof ElementAttributeValues>() : Promise\<Array\<T>>;
794
795Obtains all attribute names of this element. This API uses a promise to return the result.
796
797> **NOTE**
798>
799> This API is deprecated since API version 12.
800
801**System capability**: SystemCapability.BarrierFree.Accessibility.Core
802
803**Return value**
804
805| Type                           | Description                      |
806| ----------------------------- | ------------------------ |
807| Promise&lt;Array&lt;T&gt;&gt; | Promise used to return all attribute names of the element.|
808
809**Example**
810
811```ts
812import { ElementAttributeKeys } from '@kit.AccessibilityKit';
813import { BusinessError } from '@kit.BasicServicesKit';
814
815// rootElement is an instance of AccessibilityElement.
816rootElement.attributeNames().then((data: ElementAttributeKeys[]) => {
817  console.log(`Succeeded in get attribute names, ${JSON.stringify(data)}`);
818}).catch((err: BusinessError) => {
819  console.log(`failed to get attribute names, Code is ${err.code}, message is ${err.message}`);
820});
821```
822
823### attributeNames<sup>(deprecated)</sup>
824
825attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\<Array\<T>>): void;
826
827Obtains all attribute names of this element. This API uses an asynchronous callback to return the result.
828
829> **NOTE**
830>
831> This API is deprecated since API version 12.
832
833**System capability**: SystemCapability.BarrierFree.Accessibility.Core
834
835**Parameters**
836
837| Name     | Type                                 | Mandatory  | Description                 |
838| -------- | ----------------------------------- | ---- | ------------------- |
839| callback | AsyncCallback&lt;Array&lt;T&gt;&gt; | Yes   | Callback used to return all attribute names of the element.|
840
841**Example**
842
843```ts
844import { ElementAttributeKeys } from '@kit.AccessibilityKit';
845import { BusinessError } from '@kit.BasicServicesKit';
846
847// rootElement is an instance of AccessibilityElement.
848rootElement.attributeNames((err: BusinessError, data: ElementAttributeKeys[]) => {
849  if (err && err.code) {
850    console.error(`failed to get attribute names, Code is ${err.code}, message is ${err.message}`);
851    return;
852  }
853  console.info(`Succeeded in get attribute names, ${JSON.stringify(data)}`);
854});
855```
856
857### attributeValue<sup>(deprecated)</sup>
858
859attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promise\<ElementAttributeValues[T]>;
860
861Obtains the attribute value based on an attribute name. This API uses a promise to return the result.
862
863> **NOTE**
864>
865> This API is deprecated since API version 12.
866
867**System capability**: SystemCapability.BarrierFree.Accessibility.Core
868
869
870**Parameters**
871
872| Name          | Type  | Mandatory  | Description      |
873| ------------- | ---- | ---- | -------- |
874| attributeName | ElementAttributeKeys  | Yes   | Attribute name.|
875
876**Return value**
877
878| Type                                      | Description                         |
879| ---------------------------------------- | --------------------------- |
880| Promise&lt;ElementAttributeValues[T]&gt; | Promise used to return the attribute value.|
881
882**Error codes**
883
884For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
885
886| ID  | Error Message                         |
887| ------- | ----------------------------- |
888| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
889| 9300004 | This property does not exist. |
890
891
892**Example**
893
894```ts
895import { ElementAttributeKeys } from '@kit.AccessibilityKit';
896import { BusinessError } from '@kit.BasicServicesKit';
897
898let attributeName: ElementAttributeKeys = 'bundleName';
899
900// rootElement is an instance of AccessibilityElement.
901rootElement.attributeValue(attributeName).then((data: string) => {
902  console.log(`Succeeded in get attribute value by name, ${JSON.stringify(data)}`);
903}).catch((err: BusinessError) => {
904  console.error(`failed to get attribute value, Code is ${err.code}, message is ${err.message}`);
905});
906```
907
908### attributeValue<sup>(deprecated)</sup>
909
910attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T,
911    callback: AsyncCallback\<ElementAttributeValues[T]>): void;
912
913Obtains the attribute value based on an attribute name. This API uses an asynchronous callback to return the result.
914
915> **NOTE**
916>
917> This API is deprecated since API version 12.
918
919**System capability**: SystemCapability.BarrierFree.Accessibility.Core
920
921**Parameters**
922
923| Name          | Type                                      | Mandatory  | Description                    |
924| ------------- | ---------------------------------------- | ---- | ---------------------- |
925| attributeName | ElementAttributeKeys                         | Yes   | Attribute name.              |
926| callback      | AsyncCallback&lt;ElementAttributeValues[T]&gt; | Yes   | Callback used to return the attribute value.|
927
928**Error codes**
929
930For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
931
932| ID  | Error Message                         |
933| ------- | ----------------------------- |
934| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
935| 9300004 | This property does not exist. |
936
937**Example**
938
939```ts
940import { ElementAttributeKeys } from '@kit.AccessibilityKit';
941import { BusinessError } from '@kit.BasicServicesKit';
942
943let attributeName: ElementAttributeKeys = 'bundleName';
944
945// rootElement is an instance of AccessibilityElement.
946rootElement.attributeValue(attributeName, (err: BusinessError, data: string) => {
947  if (err && err.code) {
948    console.error(`failed to get attribute value, Code is ${err.code}, message is ${err.message}`);
949    return;
950  }
951  console.info(`Succeeded in get attribute value, ${JSON.stringify(data)}`);
952});
953```
954
955### actionNames<sup>(deprecated)</sup>
956
957actionNames(): Promise\<Array\<string>>;
958
959Obtains the names of all actions supported by this element. This API uses a promise to return the result.
960
961> **NOTE**
962>
963> This API is deprecated since API version 12.
964
965**System capability**: SystemCapability.BarrierFree.Accessibility.Core
966
967**Return value**
968
969| Type                                | Description                        |
970| ---------------------------------- | -------------------------- |
971| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the names of all actions supported by the element.|
972
973**Example**
974
975```ts
976import { BusinessError } from '@kit.BasicServicesKit';
977
978// rootElement is an instance of AccessibilityElement.
979rootElement.actionNames().then((data: string[]) => {
980  console.log(`Succeeded in get action names, ${JSON.stringify(data)}`);
981}).catch((err: BusinessError) => {
982  console.error(`failed to get action names, Code is ${err.code}, message is ${err.message}`);
983})
984```
985
986### actionNames<sup>(deprecated)</sup>
987
988actionNames(callback: AsyncCallback\<Array\<string>>): void;
989
990Obtains the names of all actions supported by this element. This API uses an asynchronous callback to return the result.
991
992> **NOTE**
993>
994> This API is deprecated since API version 12.
995
996**System capability**: SystemCapability.BarrierFree.Accessibility.Core
997
998**Parameters**
999
1000| Name     | Type                                      | Mandatory  | Description                   |
1001| -------- | ---------------------------------------- | ---- | --------------------- |
1002| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the names of all actions supported by the element.|
1003
1004**Example**
1005
1006```ts
1007// rootElement is an instance of AccessibilityElement.
1008rootElement.actionNames((err: BusinessError, data: string[]) => {
1009  if (err && err.code) {
1010    console.error(`failed to get action names, Code is ${err.code}, message is ${err.message}`);
1011    return;
1012  }
1013  console.info(`Succeeded in get action names, ${JSON.stringify(data)}`);
1014})
1015```
1016
1017### performAction<sup>(deprecated)</sup>
1018
1019performAction(actionName: string, parameters?: object): Promise\<void>;
1020
1021Performs an action based on the specified action name. This API uses a promise to return the result.
1022
1023> **NOTE**
1024>
1025> This API is deprecated since API version 12.
1026
1027**System capability**: SystemCapability.BarrierFree.Accessibility.Core
1028
1029**Parameters**
1030
1031| Name        | Type                                    | Mandatory  | Description                                                      |
1032| ----------- | ---------------------------------------- | ---- |----------------------------------------------------------|
1033| actionName | string | Yes   | Action name. For details, see [Action](./js-apis-accessibility.md#action).
1034| parameters | object | No   | Parameters required for performing the target action. Empty by default.                            |
1035
1036**Return value**
1037
1038| Type                 | Description              |
1039| ------------------- | ---------------- |
1040| Promise&lt;void&gt; | Promise that returns no value.|
1041
1042**Error codes**
1043
1044For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
1045
1046| ID  | Error Message                         |
1047| ------- | ----------------------------- |
1048| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1049| 9300005 | This action is not supported. |
1050
1051**Example**
1052
1053```ts
1054import { BusinessError } from '@kit.BasicServicesKit';
1055
1056let actionName = 'action';
1057
1058// rootElement is an instance of AccessibilityElement.
1059rootElement.performAction(actionName).then(() => {
1060  console.info(`Succeeded in perform action,actionName is ${actionName}`);
1061}).catch((err: BusinessError) => {
1062  console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`);
1063});
1064```
1065
1066**Example of an action without parameters:**
1067
1068```ts
1069import { BusinessError } from '@kit.BasicServicesKit';
1070
1071// rootElement is an instance of AccessibilityElement.
1072// An action that does not require any parameter setting is an action without parameters, as specified in the action description.
1073rootElement.performAction('click').then(() => {
1074  console.info(`Succeeded in perform action.`);
1075}).catch((err: BusinessError) => {
1076  console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`);
1077});
1078```
1079
1080**Example of an action with parameters:**
1081
1082```ts
1083import { BusinessError } from '@kit.BasicServicesKit';
1084
1085// rootElement is an instance of AccessibilityElement.
1086// Sample code of setSelection
1087rootElement.performAction('setSelection', {
1088  selectTextBegin: '0', // Indicates the start position of selection.
1089  selectTextEnd: '8',   // Indicates the end position of selection.
1090  selectTextInForWard: true   // true indicates the insertion point, and false indicates the selection range.
1091}).then(() => {
1092  console.info(`Succeeded in perform action`);
1093}).catch((err: BusinessError) => {
1094  console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`);
1095});
1096```
1097
1098```ts
1099import { BusinessError } from '@kit.BasicServicesKit';
1100
1101// rootElement is an instance of AccessibilityElement.
1102// Sample code of setCursorPosition
1103rootElement.performAction('setCursorPosition', {
1104  offset: '1'   // Position of the cursor.
1105}).then(() => {
1106  console.info(`Succeeded in perform action`);
1107}).catch((err: BusinessError) => {
1108  console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`);
1109});
1110```
1111
1112### performAction<sup>(deprecated)</sup>
1113
1114performAction(actionName: string, callback: AsyncCallback\<void>): void;
1115
1116Performs an action based on the specified action name. This API uses an asynchronous callback to return the result.
1117
1118> **NOTE**
1119>
1120> This API is deprecated since API version 12.
1121
1122**System capability**: SystemCapability.BarrierFree.Accessibility.Core
1123
1124**Parameters**
1125
1126| Name        | Type                                    | Mandatory  | Description            |
1127| ----------- | ---------------------------------------- | ---- | -------------- |
1128| actionName | string | Yes   | Action name. For details, see [Action](./js-apis-accessibility.md#action).
1129| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.|
1130
1131**Error codes**
1132
1133For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
1134
1135| ID  | Error Message                         |
1136| ------- | ----------------------------- |
1137| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1138| 9300005 | This action is not supported. |
1139
1140**Example**
1141
1142```ts
1143import { BusinessError } from '@kit.BasicServicesKit';
1144
1145let actionName = 'action';
1146
1147// rootElement is an instance of AccessibilityElement.
1148rootElement.performAction(actionName, (err: BusinessError) => {
1149  if (err && err.code) {
1150    console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`);
1151    return;
1152  }
1153  console.info(`Succeeded in perform action, actionName is ${actionName}`);
1154});
1155```
1156
1157### performAction<sup>(deprecated)</sup>
1158
1159performAction(actionName: string, parameters: object, callback: AsyncCallback\<void>): void;
1160
1161Performs an action based on the specified action name. This API uses an asynchronous callback to return the result.
1162
1163> **NOTE**
1164>
1165> This API is deprecated since API version 12.
1166
1167**System capability**: SystemCapability.BarrierFree.Accessibility.Core
1168
1169**Parameters**
1170
1171| Name       | Type                       | Mandatory  | Description                                                         |
1172| ---------- | ------------------------- | ---- |-------------------------------------------------------------|
1173| actionName | string                    | Yes   | Action name. For details, see [Action](./js-apis-accessibility.md#action).|
1174| parameters | object                    | Yes   | Parameters required for performing the target action. Empty by default.                               |
1175| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.                                          |
1176
1177**Error codes**
1178
1179For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
1180
1181| ID  | Error Message                         |
1182| ------- | ----------------------------- |
1183| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1184| 9300005 | This action is not supported. |
1185
1186**Example**
1187
1188```ts
1189import { BusinessError } from '@kit.BasicServicesKit';
1190
1191let actionName = 'action';
1192let parameters: object = [];
1193
1194// rootElement is an instance of AccessibilityElement.
1195rootElement.performAction(actionName, parameters, (err: BusinessError) => {
1196  if (err && err.code) {
1197    console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`);
1198    return;
1199  }
1200  console.info(`Succeeded in perform action,actionName is ${actionName}, parameters is ${parameters}`);
1201});
1202```
1203
1204### findElement('content')<sup>(deprecated)</sup>
1205
1206findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityElement>>;
1207
1208Finds an element based on the content type. This API uses a promise to return the result.
1209
1210> **NOTE**
1211>
1212> This API is deprecated since API version 12.
1213
1214**System capability**: SystemCapability.BarrierFree.Accessibility.Core
1215
1216**Parameters**
1217
1218| Name      | Type    | Mandatory  | Description                           |
1219| --------- | ------ | ---- | ----------------------------- |
1220| type      | string | Yes   | Type of element finding. The value is fixed at **'content'**.|
1221| condition | string | Yes   | Search criteria.                     |
1222
1223**Return value**
1224
1225| Type                                      | Description                           |
1226| ---------------------------------------- | ----------------------------- |
1227| Promise&lt;Array&lt;[AccessibilityElement](#accessibilityelement9)&gt;&gt; | Promise used to return the result.|
1228
1229**Error codes**
1230
1231For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
1232
1233| ID  | Error Message                         |
1234| ------- | ----------------------------- |
1235| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1236
1237**Example**
1238
1239```ts
1240import { BusinessError } from '@kit.BasicServicesKit';
1241
1242let condition = 'keyword';
1243
1244// rootElement is an instance of AccessibilityElement.
1245rootElement.findElement('content', condition).then((data: AccessibilityElement[]) => {
1246  console.log(`Succeeded in find element, ${JSON.stringify(data)}`);
1247}).catch((err: BusinessError) => {
1248  console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`);
1249});
1250```
1251
1252### findElement('content')<sup>(deprecated)</sup>
1253
1254findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\<AccessibilityElement>>): void;
1255
1256Finds an element based on the content type. This API uses an asynchronous callback to return the result.
1257
1258> **NOTE**
1259>
1260> This API is deprecated since API version 12.
1261
1262**System capability**: SystemCapability.BarrierFree.Accessibility.Core
1263
1264**Parameters**
1265
1266| Name      | Type                                      | Mandatory  | Description                          |
1267| --------- | ---------------------------------------- | ---- | ---------------------------- |
1268| type      | string                                   | Yes   | Type of element finding. The value is fixed at **'content'**.|
1269| condition | string                                   | Yes   | Search criteria.                    |
1270| callback  | AsyncCallback&lt;Array&lt;[AccessibilityElement](#accessibilityelement9)&gt;&gt; | Yes   | Callback used to return the result.    |
1271
1272**Error codes**
1273
1274For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
1275
1276| ID  | Error Message                         |
1277| ------- | ----------------------------- |
1278| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1279
1280**Example**
1281
1282```ts
1283import { BusinessError } from '@kit.BasicServicesKit';
1284
1285let condition = 'keyword';
1286
1287// rootElement is an instance of AccessibilityElement.
1288rootElement.findElement('content', condition, (err: BusinessError, data: AccessibilityElement[])=>{
1289  if (err && err.code) {
1290    console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`);
1291    return;
1292  }
1293  console.info(`Succeeded in find element, ${JSON.stringify(data)}`);
1294});
1295```
1296
1297### findElement('focusType')<sup>(deprecated)</sup>
1298
1299findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElement>;
1300
1301Finds an element based on the focus type. This API uses a promise to return the result.
1302
1303> **NOTE**
1304>
1305> This API is deprecated since API version 12.
1306
1307**System capability**: SystemCapability.BarrierFree.Accessibility.Core
1308
1309**Parameters**
1310
1311| Name      | Type                     | Mandatory  | Description                                |
1312| --------- | ----------------------- | ---- | ---------------------------------- |
1313| type      | string                  | Yes   | Type of element finding. The value is fixed at **'focusType'**.|
1314| condition | [FocusType](#focustype) | Yes   | Focus type.                      |
1315
1316**Return value**
1317
1318| Type                                 | Description                            |
1319| ----------------------------------- | ------------------------------ |
1320| Promise&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Promise used to return the result.|
1321
1322**Error codes**
1323
1324For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
1325
1326| ID  | Error Message                         |
1327| ------- | ----------------------------- |
1328| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1329
1330**Example**
1331
1332```ts
1333import { FocusType } from '@kit.AccessibilityKit';
1334import { BusinessError } from '@kit.BasicServicesKit';
1335
1336let condition: FocusType = 'normal';
1337
1338// rootElement is an instance of AccessibilityElement.
1339rootElement.findElement('focusType', condition).then((data: AccessibilityElement) => {
1340  console.log(`Succeeded in find element,${JSON.stringify(data)}`);
1341}).catch((err: BusinessError) => {
1342  console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`);
1343});
1344```
1345
1346### findElement('focusType')<sup>(deprecated)</sup>
1347
1348findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<AccessibilityElement>): void;
1349
1350Finds an element based on the focus type. This API uses an asynchronous callback to return the result.
1351
1352> **NOTE**
1353>
1354> This API is deprecated since API version 12.
1355
1356**System capability**: SystemCapability.BarrierFree.Accessibility.Core
1357
1358**Parameters**
1359
1360| Name      | Type                                      | Mandatory  | Description                                |
1361| --------- | ---------------------------------------- | ---- | ---------------------------------- |
1362| type      | string                                   | Yes   | Type of element finding. The value is fixed at **'focusType'**.|
1363| condition | [FocusType](#focustype)                  | Yes   | Focus type.                      |
1364| callback  | AsyncCallback&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Yes   | Callback used to return the result.         |
1365
1366**Error codes**
1367
1368For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
1369
1370| ID  | Error Message                         |
1371| ------- | ----------------------------- |
1372| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1373
1374**Example**
1375
1376```ts
1377import { FocusType } from '@kit.AccessibilityKit';
1378import { BusinessError } from '@kit.BasicServicesKit';
1379
1380let condition: FocusType = 'normal';
1381
1382// rootElement is an instance of AccessibilityElement.
1383rootElement.findElement('focusType', condition, (err: BusinessError, data: AccessibilityElement)=>{
1384  if (err && err.code) {
1385    console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`);
1386    return;
1387  }
1388  console.info(`Succeeded in find element, ${JSON.stringify(data)}`);
1389});
1390```
1391
1392### findElement('focusDirection')<sup>(deprecated)</sup>
1393
1394findElement(type: 'focusDirection', condition: FocusDirection): Promise\<AccessibilityElement>;
1395
1396Finds an element based on the focus direction. This API uses a promise to return the result.
1397
1398> **NOTE**
1399>
1400> This API is deprecated since API version 12.
1401
1402**System capability**: SystemCapability.BarrierFree.Accessibility.Core
1403
1404**Parameters**
1405
1406| Name      | Type                               | Mandatory  | Description                                      |
1407| --------- | --------------------------------- | ---- | ---------------------------------------- |
1408| type      | string                            | Yes   | Type of element finding. The value is fixed at **'focusDirection'**.|
1409| condition | [FocusDirection](#focusdirection) | Yes   | Focus direction.                          |
1410
1411**Return value**
1412
1413| Type                                 | Description                              |
1414| ----------------------------------- | -------------------------------- |
1415| Promise&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Promise used to return the result.|
1416
1417**Error codes**
1418
1419For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
1420
1421| ID  | Error Message                         |
1422| ------- | ----------------------------- |
1423| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1424
1425**Example**
1426
1427```ts
1428import { FocusDirection } from '@kit.AccessibilityKit';
1429import { BusinessError } from '@kit.BasicServicesKit';
1430
1431let condition: FocusDirection = 'up';
1432
1433// rootElement is an instance of AccessibilityElement.
1434rootElement.findElement('focusDirection', condition).then((data: AccessibilityElement) => {
1435  console.log(`Succeeded in find element, ${JSON.stringify(data)}`);
1436}).catch((err: BusinessError) => {
1437  console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`);
1438});
1439```
1440
1441### findElement('focusDirection')<sup>(deprecated)</sup>
1442
1443findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCallback\<AccessibilityElement>): void;
1444
1445Finds an element based on the focus direction. This API uses an asynchronous callback to return the result.
1446
1447> **NOTE**
1448>
1449> This API is deprecated since API version 12.
1450
1451**System capability**: SystemCapability.BarrierFree.Accessibility.Core
1452
1453**Parameters**
1454
1455| Name      | Type                                      | Mandatory  | Description                                      |
1456| --------- | ---------------------------------------- | ---- | ---------------------------------------- |
1457| type      | string                                   | Yes   | Type of element finding. The value is fixed at **'focusDirection'**.|
1458| condition | [FocusDirection](#focusdirection)        | Yes   | Direction of the next focus element.                          |
1459| callback  | AsyncCallback&lt;[AccessibilityElement](#accessibilityelement9)&gt; | Yes   | Callback used to return the result.             |
1460
1461**Error codes**
1462
1463For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md).
1464
1465| ID  | Error Message                         |
1466| ------- | ----------------------------- |
1467| 401  |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1468
1469**Example**
1470
1471```ts
1472import { FocusDirection } from '@kit.AccessibilityKit';
1473import { BusinessError } from '@kit.BasicServicesKit';
1474
1475let condition: FocusDirection = 'up';
1476
1477// rootElement is an instance of AccessibilityElement.
1478rootElement.findElement('focusDirection', condition, (err: BusinessError, data: AccessibilityElement) =>{
1479  if (err && err.code) {
1480    console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`);
1481    return;
1482  }
1483  console.info(`Succeeded in find element, ${JSON.stringify(data)}`);
1484});
1485```
1486