js-apis-uitest.md 121.2 KB
Newer Older
E
ester.zhou 已提交
1
# @ohos.UiTest
E
add doc  
ester.zhou 已提交
2

E
esterzhou 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15
The **UiTest** module provides APIs that you can use to simulate UI actions during testing, such as clicks, double-clicks, long-clicks, and swipes.

This module provides the following functions:

- [On<sup>9+</sup>](#on9): provides UI component feature description APIs for component filtering and matching.
- [Component<sup>9+</sup>](#component9): represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection.
- [Driver<sup>9+</sup>](#driver9): works as the entry class and provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot.
- [UiWindow<sup>9+</sup>](#uiwindow9): works as the entry class and provides APIs for obtaining window attributes, dragging windows, and adjusting window sizes.
- [By<sup>(deprecated)</sup>](#bydeprecated): provides UI component feature description APIs for component filtering and matching. This API is deprecated since API version 9. You are advised to use [On<sup>9+</sup>](#on9) instead.
- [UiComponent<sup>(deprecated)</sup>](#uicomponentdeprecated): represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection. This API is deprecated since API version 9. You are advised to use [Component<sup>9+</sup>](#component9) instead.
- [UiDriver<sup>(deprecated)</sup>](#uidriverdeprecated): works as the entry class and provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot. This API is deprecated since API version 9. You are advised to use [Driver<sup>9+</sup>](#driver9) instead.

>**NOTE**
E
add doc  
ester.zhou 已提交
16
>
E
esterzhou 已提交
17
>The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
E
add doc  
ester.zhou 已提交
18 19 20 21


## Modules to Import

E
esterzhou 已提交
22
```js
E
ester.zhou 已提交
23
import {UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern, DisplayRotation, ResizeDirection, WindowMode, PointerMatrix, UiDirection, MouseButton} from '@ohos.UiTest';
E
add doc  
ester.zhou 已提交
24 25
```

E
esterzhou 已提交
26
## MatchPattern
E
add doc  
ester.zhou 已提交
27

E
esterzhou 已提交
28
Enumerates the match patterns supported for component attributes.
E
add doc  
ester.zhou 已提交
29

E
esterzhou 已提交
30
**System capability**: SystemCapability.Test.UiTest
E
add doc  
ester.zhou 已提交
31

E
esterzhou 已提交
32 33
| Name       | Value  | Description          |
| ----------- | ---- | -------------- |
E
ester.zhou 已提交
34
| EQUALS      | 0    | Equals the given value.  |
E
esterzhou 已提交
35 36 37
| CONTAINS    | 1    | Contains the given value.  |
| STARTS_WITH | 2    | Starts with the given value.|
| ENDS_WITH   | 3    | Ends with the given value.|
E
add doc  
ester.zhou 已提交
38

E
esterzhou 已提交
39
## ResizeDirection<sup>9+</sup>
E
add doc  
ester.zhou 已提交
40

E
esterzhou 已提交
41
Enumerates the directions in which a window can be resized.
E
add doc  
ester.zhou 已提交
42 43 44

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
45 46 47 48 49 50 51 52 53 54
| Name      | Value  | Description    |
| ---------- | ---- | -------- |
| LEFT       | 0    | Left.  |
| RIGHT      | 1    | Right.  |
| UP         | 2    | Up.  |
| DOWN       | 3    | Down.  |
| LEFT_UP    | 4    | Upper left.|
| LEFT_DOWN  | 5    | Lower left.|
| RIGHT_UP   | 6    | Upper right.|
| RIGHT_DOWN | 7    | Lower right.|
E
add doc  
ester.zhou 已提交
55

E
esterzhou 已提交
56
## Point<sup>9+</sup>
E
add doc  
ester.zhou 已提交
57

E
esterzhou 已提交
58
Provides the coordinates of a point.
E
add doc  
ester.zhou 已提交
59

E
esterzhou 已提交
60
**System capability**: SystemCapability.Test.UiTest
E
add doc  
ester.zhou 已提交
61

E
esterzhou 已提交
62 63
| Name| Type  | Readable| Writable| Description            |
| ---- | ------ | ---- | ---- | ---------------- |
E
ester.zhou 已提交
64 65
| x    | number | Yes  | No  | X-coordinate of a point.|
| y    | number | Yes  | No  | Y-coordinate of a point.|
E
esterzhou 已提交
66 67 68 69 70 71 72

## Rect<sup>9+</sup>

Provides bounds information of a component.

**System capability**: SystemCapability.Test.UiTest

E
ester.zhou 已提交
73 74 75 76 77 78
| Name  | Type  | Readable| Writable| Description                     |
| ------ | ------ | ---- | ---- | ------------------------- |
| left   | number | Yes  | No  | X-coordinate of the upper left corner of the component bounds.|
| top    | number | Yes  | No  | Y-coordinate of the upper left corner of the component bounds.|
| right  | number | Yes  | No  | X-coordinate of the lower right corner of the component bounds.|
| bottom | number | Yes  | No  | Y-coordinate of the lower right corner of the component bounds.|
E
esterzhou 已提交
79 80 81 82 83

## WindowMode<sup>9+</sup>

Enumerates the window modes.

E
ester.zhou 已提交
84 85
**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
86 87 88 89 90 91 92 93 94 95 96
| Name      | Value  | Description      |
| ---------- | ---- | ---------- |
| FULLSCREEN | 0    | Full-screen mode.|
| PRIMARY    | 1    | Primary window mode.  |
| SECONDARY  | 2    | Secondary window mode.|
| FLOATING   | 3    | Floating window mode.|

## DisplayRotation<sup>9+</sup>

Describes the display rotation of the device.

E
ester.zhou 已提交
97 98
**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| Name        | Value  | Description                                    |
| ------------ | ---- | ---------------------------------------- |
| ROTATION_0   | 0    | The device display is not rotated and is in its original vertical orientation.    |
| ROTATION_90  | 1    | The device display rotates 90° clockwise and is in landscape orientation.     |
| ROTATION_180 | 2    | The device display rotates 180° clockwise and is in reverse vertical orientation.|
| ROTATION_270 | 3    | The device display rotates 270° clockwise and is in reverse landscape orientation.|

## WindowFilter<sup>9+</sup>

Provides the flag attributes of this window.

**System capability**: SystemCapability.Test.UiTest

| Name      | Type   | Readable| Writable| Description                      |
| ---------- | ------- | ---- | ---- | -------------------------- |
| bundleName | string  | Yes  | No  | Bundle name of the application to which the window belongs.      |
| title      | string  | Yes  | No  | Title of the window.          |
| focused    | boolean | Yes  | No  | Whether the window is in focused state.    |
| actived    | boolean | Yes  | No  | Whether the window is interacting with the user.|

E
ester.zhou 已提交
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
## UiDirection<sup>10+</sup>

Describes the direction of a UI operation such as fling.

**System capability**: SystemCapability.Test.UiTest

| Name | Value  | Description  |
| ----- | ---- | ------ |
| LEFT  | 0    | Leftward.|
| RIGHT | 1    | Rightward.|
| UP    | 2    | Upward.|
| DOWN  | 3    | Downward.|

## MouseButton<sup>10+</sup>

Describes the injected simulated mouse button.

**System capability**: SystemCapability.Test.UiTest

| Name               | Value  | Description        |
| ------------------- | ---- | ------------ |
| MOUSE_BUTTON_LEFT   | 0    | Left button on the mouse.  |
| MOUSE_BUTTON_RIGHT  | 1    | Right button on the mouse.  |
| MOUSE_BUTTON_MIDDLE | 2    | Middle button on the mouse.|

E
esterzhou 已提交
144 145 146
## On<sup>9+</sup>

Since API version 9, the UiTest framework provides a wide range of UI component feature description APIs in the **On** class to filter and match components.
E
ester.zhou 已提交
147
The API capabilities provided by the **On** class exhibit the following features: 1. Allow one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component. <br>2. Provide multiple match patterns for component attributes. <br>3. Support absolute positioning and relative positioning for components. APIs such as [ON.isBefore](#isbefore9) and [ON.isAfter](#isafter9) can be used to specify the features of adjacent components to assist positioning. <br>All APIs provided in the **On** class are synchronous. You are advised to use the static constructor **ON** to create an **On** object in chain mode.
E
add doc  
ester.zhou 已提交
148

E
ester.zhou 已提交
149
```js
E
esterzhou 已提交
150
ON.text('123').type('button');
E
add doc  
ester.zhou 已提交
151 152
```

E
esterzhou 已提交
153
### text<sup>9+</sup>
E
add doc  
ester.zhou 已提交
154

E
esterzhou 已提交
155
text(txt: string, pattern?: MatchPattern): On
E
add doc  
ester.zhou 已提交
156

E
esterzhou 已提交
157
Specifies the text attribute of the target component. Multiple match patterns are supported.
E
add doc  
ester.zhou 已提交
158 159 160 161 162

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
163 164 165 166
| Name | Type                         | Mandatory| Description                                               |
| ------- | ----------------------------- | ---- | --------------------------------------------------- |
| txt     | string                        | Yes  | Component text, used to match the target component.               |
| pattern | [MatchPattern](#matchpattern) | No  | Match pattern. The default value is [EQUALS](#matchpattern).|
E
add doc  
ester.zhou 已提交
167 168 169

**Return value**

E
esterzhou 已提交
170 171 172
| Type      | Description                              |
| ---------- | ---------------------------------- |
| [On](#on9) | **On** object that matches the text attribute of the target component.|
E
add doc  
ester.zhou 已提交
173 174 175

**Example**

E
ester.zhou 已提交
176
```js
E
esterzhou 已提交
177
let on = ON.text('123'); // Use the static constructor ON to create an On object and specify the text attribute of the target component.
E
add doc  
ester.zhou 已提交
178 179 180
```


E
esterzhou 已提交
181
### id<sup>9+</sup>
E
add doc  
ester.zhou 已提交
182

E
esterzhou 已提交
183
id(id: string): On
E
add doc  
ester.zhou 已提交
184

E
ester.zhou 已提交
185
Specifies the ID attribute of the target component.
E
add doc  
ester.zhou 已提交
186 187 188 189 190

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
191 192
| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
E
esterzhou 已提交
193
| id     | string | Yes  | Component ID.|
E
add doc  
ester.zhou 已提交
194 195 196

**Return value**

E
esterzhou 已提交
197 198 199
| Type      | Description                            |
| ---------- | -------------------------------- |
| [On](#on9) | **On** object that matches the ID attribute of the target component.|
E
add doc  
ester.zhou 已提交
200 201 202

**Example**

E
ester.zhou 已提交
203
```js
E
esterzhou 已提交
204
let on = ON.id('123'); // Use the static constructor ON to create an On object and specify the ID attribute of the target component.
E
add doc  
ester.zhou 已提交
205 206 207
```


E
esterzhou 已提交
208
### type<sup>9+</sup>
E
add doc  
ester.zhou 已提交
209

E
esterzhou 已提交
210
type(tp: string): On
E
add doc  
ester.zhou 已提交
211

E
ester.zhou 已提交
212
Specifies the type attribute of the target component.
E
add doc  
ester.zhou 已提交
213 214 215 216 217

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
218 219
| Name| Type  | Mandatory| Description          |
| ------ | ------ | ---- | -------------- |
E
add doc  
ester.zhou 已提交
220 221 222 223
| tp     | string | Yes  | Component type.|

**Return value**

E
esterzhou 已提交
224 225 226
| Type      | Description                                    |
| ---------- | ---------------------------------------- |
| [On](#on9) | **On** object that matches the type attribute of the target component.|
E
add doc  
ester.zhou 已提交
227 228 229

**Example**

E
ester.zhou 已提交
230
```js
E
esterzhou 已提交
231
let on = ON.type('button'); // Use the static constructor ON to create an On object and specify the type attribute of the target component.
E
add doc  
ester.zhou 已提交
232 233 234
```


E
esterzhou 已提交
235
### clickable<sup>9+</sup>
E
add doc  
ester.zhou 已提交
236

E
esterzhou 已提交
237
clickable(b?: boolean): On
E
add doc  
ester.zhou 已提交
238

E
esterzhou 已提交
239
Specifies the clickable status attribute of the target component.
E
add doc  
ester.zhou 已提交
240 241 242 243 244

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
245 246
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
E
ester.zhou 已提交
247
| b      | boolean | No  | Clickable status of the target component.<br>**true**: clickable.<br>**false**: not clickable.<br>Default value: **true** |
E
add doc  
ester.zhou 已提交
248 249 250

**Return value**

E
esterzhou 已提交
251 252 253
| Type      | Description                                      |
| ---------- | ------------------------------------------ |
| [On](#on9) | **On** object that matches the clickable status attribute of the target component.|
E
add doc  
ester.zhou 已提交
254 255 256

**Example**

E
ester.zhou 已提交
257
```js
E
esterzhou 已提交
258
let on = ON.clickable(true); // Use the static constructor ON to create an On object and specify the clickable status attribute of the target component.
E
add doc  
ester.zhou 已提交
259
```
E
ester.zhou 已提交
260

E
esterzhou 已提交
261
### longClickable<sup>9+</sup>
E
ester.zhou 已提交
262

E
esterzhou 已提交
263
longClickable(b?: boolean): On
E
ester.zhou 已提交
264 265 266 267 268 269 270

Specifies the long-clickable status attribute of the target component.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
271 272
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
E
ester.zhou 已提交
273
| b      | boolean | No  | Long-clickable status of the target component.<br>**true**: long-clickable.<br>**false**: not long-clickable.<br>Default value: **true** |
E
ester.zhou 已提交
274 275 276

**Return value**

E
esterzhou 已提交
277 278 279
| Type      | Description                                          |
| ---------- | ---------------------------------------------- |
| [On](#on9) | **On** object that matches the long-clickable status attribute of the target component.|
E
ester.zhou 已提交
280 281 282 283

**Example**

```js
E
esterzhou 已提交
284
let on = ON.longClickable(true); // Use the static constructor ON to create an On object and specify the long-clickable status attribute of the target component.
E
add doc  
ester.zhou 已提交
285 286 287
```


E
esterzhou 已提交
288
### scrollable<sup>9+</sup>
E
add doc  
ester.zhou 已提交
289

E
esterzhou 已提交
290
scrollable(b?: boolean): On
E
add doc  
ester.zhou 已提交
291

E
ester.zhou 已提交
292
Specifies the scrollable status attribute of the target component.
E
add doc  
ester.zhou 已提交
293 294 295 296 297

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
298 299
| Name| Type   | Mandatory| Description                                                       |
| ------ | ------- | ---- | ----------------------------------------------------------- |
E
ester.zhou 已提交
300
| b      | boolean | No  | Scrollable status of the target component.<br>**true**: scrollable.<br>**false**: not scrollable.<br>Default value: **true** |
E
add doc  
ester.zhou 已提交
301 302 303

**Return value**

E
esterzhou 已提交
304 305 306
| Type      | Description                                      |
| ---------- | ------------------------------------------ |
| [On](#on9) | **On** object that matches the scrollable status attribute of the target component.|
E
add doc  
ester.zhou 已提交
307 308 309

**Example**

E
ester.zhou 已提交
310
```js
E
esterzhou 已提交
311
let on = ON.scrollable(true); // Use the static constructor ON to create an On object and specify the scrollable status attribute of the target component.
E
add doc  
ester.zhou 已提交
312 313
```

E
esterzhou 已提交
314
### enabled<sup>9+</sup>
E
add doc  
ester.zhou 已提交
315

E
esterzhou 已提交
316
enabled(b?: boolean): On
E
add doc  
ester.zhou 已提交
317

E
ester.zhou 已提交
318
Specifies the enabled status attribute of the target component.
E
add doc  
ester.zhou 已提交
319 320 321 322 323

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
324 325
| Name| Type   | Mandatory| Description                                                     |
| ------ | ------- | ---- | --------------------------------------------------------- |
E
ester.zhou 已提交
326
| b      | boolean | No  | Enabled status of the target component.<br>**true**: enabled.<br>**false**: not enabled.<br>Default value: **true** |
E
add doc  
ester.zhou 已提交
327 328 329

**Return value**

E
esterzhou 已提交
330 331 332
| Type      | Description                                    |
| ---------- | ---------------------------------------- |
| [On](#on9) | **On** object that matches the enabled status attribute of the target component.|
E
add doc  
ester.zhou 已提交
333 334 335

**Example**

E
ester.zhou 已提交
336
```js
E
esterzhou 已提交
337
let on = ON.enabled(true); // Use the static constructor ON to create an On object and specify the enabled status attribute of the target component.
E
add doc  
ester.zhou 已提交
338 339
```

E
esterzhou 已提交
340
### focused<sup>9+</sup>
E
add doc  
ester.zhou 已提交
341

E
esterzhou 已提交
342
focused(b?: boolean): On
E
add doc  
ester.zhou 已提交
343

E
ester.zhou 已提交
344
Specifies the focused status attribute of the target component.
E
add doc  
ester.zhou 已提交
345 346 347 348 349

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
350 351
| Name| Type   | Mandatory| Description                                                 |
| ------ | ------- | ---- | ----------------------------------------------------- |
E
ester.zhou 已提交
352
| b      | boolean | No  | Focused status of the target component.<br>**true**: focused.<br>**false**: not focused.<br>Default value: **true** |
E
add doc  
ester.zhou 已提交
353 354 355

**Return value**

E
esterzhou 已提交
356 357 358
| Type      | Description                                    |
| ---------- | ---------------------------------------- |
| [On](#on9) | **On** object that matches the focused status attribute of the target component.|
E
add doc  
ester.zhou 已提交
359 360 361

**Example**

E
ester.zhou 已提交
362
```js
E
esterzhou 已提交
363
let on = ON.focused(true); // Use the static constructor ON to create an On object and specify the focused status attribute of the target component.
E
add doc  
ester.zhou 已提交
364 365
```

E
esterzhou 已提交
366
### selected<sup>9+</sup>
E
add doc  
ester.zhou 已提交
367

E
esterzhou 已提交
368
selected(b?: boolean): On
E
add doc  
ester.zhou 已提交
369

E
ester.zhou 已提交
370
Specifies the selected status attribute of the target component.
E
add doc  
ester.zhou 已提交
371 372 373 374 375

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
376 377
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
E
ester.zhou 已提交
378
| b      | boolean | No  | Selected status of the target component.<br>**true**: selected.<br>**false**: not selected.<br>Default value: **true** |
E
add doc  
ester.zhou 已提交
379 380 381

**Return value**

E
esterzhou 已提交
382 383 384
| Type      | Description                                      |
| ---------- | ------------------------------------------ |
| [On](#on9) | **On** object that matches the selected status attribute of the target component.|
E
ester.zhou 已提交
385 386 387 388

**Example**

```js
E
esterzhou 已提交
389
let on = ON.selected(true); // Use the static constructor ON to create an On object and specify the selected status attribute of the target component.
E
ester.zhou 已提交
390 391
```

E
esterzhou 已提交
392
### checked<sup>9+</sup>
E
ester.zhou 已提交
393

E
esterzhou 已提交
394
checked(b?: boolean): On
E
ester.zhou 已提交
395 396 397 398 399 400 401

Specifies the checked status attribute of the target component.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
402 403
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
E
ester.zhou 已提交
404
| b      | boolean | No  | Checked status of the target component.<br>**true**: checked.<br>**false**: not checked.<br>Default value: **false** |
E
ester.zhou 已提交
405 406 407

**Return value**

E
esterzhou 已提交
408 409 410
| Type      | Description                                      |
| ---------- | ------------------------------------------ |
| [On](#on9) | **On** object that matches the checked status attribute of the target component.|
E
add doc  
ester.zhou 已提交
411 412 413

**Example**

E
ester.zhou 已提交
414
```js
E
esterzhou 已提交
415
let on = ON.checked(true); // Use the static constructor ON to create an On object and specify the checked status attribute of the target component.
E
add doc  
ester.zhou 已提交
416
```
E
ester.zhou 已提交
417

E
esterzhou 已提交
418
### checkable<sup>9+</sup>
E
ester.zhou 已提交
419

E
esterzhou 已提交
420
checkable(b?: boolean): On
E
ester.zhou 已提交
421 422 423 424 425 426 427

Specifies the checkable status attribute of the target component.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
428 429
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
E
ester.zhou 已提交
430
| b      | boolean | No  | Checkable status of the target component.<br>**true**: checkable.<br>**false**: not checkable.<br>Default value: **false** |
E
ester.zhou 已提交
431 432 433

**Return value**

E
esterzhou 已提交
434 435 436
| Type      | Description                                        |
| ---------- | -------------------------------------------- |
| [On](#on9) | **On** object that matches the checkable status attribute of the target component.|
E
ester.zhou 已提交
437 438 439 440

**Example**

```js
E
esterzhou 已提交
441
let on = ON.checkable(true); // Use the static constructor ON to create an On object and specify the checkable status attribute of the target component.
E
add doc  
ester.zhou 已提交
442 443
```

E
esterzhou 已提交
444
### isBefore<sup>9+</sup>
E
add doc  
ester.zhou 已提交
445

E
esterzhou 已提交
446
isBefore(on: On): On
E
add doc  
ester.zhou 已提交
447

E
ester.zhou 已提交
448
Specifies that the target component is located before the given attribute component.
E
add doc  
ester.zhou 已提交
449 450 451 452 453

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
454 455
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
E
ester.zhou 已提交
456
| on     | [On](#on9) | Yes  | Information about the attribute component.|
E
add doc  
ester.zhou 已提交
457 458 459

**Return value**

E
esterzhou 已提交
460 461 462
| Type      | Description                                                |
| ---------- | ---------------------------------------------------- |
| [On](#on9) | **On** object.|
E
add doc  
ester.zhou 已提交
463 464 465

**Example**

E
ester.zhou 已提交
466
```js
E
ester.zhou 已提交
467
let on = ON.isBefore(ON.text('123')); // Create an On object using the static constructor ON, specifying that the target component is located before the given attribute component.
E
add doc  
ester.zhou 已提交
468 469
```

E
esterzhou 已提交
470
### isAfter<sup>9+</sup>
E
add doc  
ester.zhou 已提交
471

E
esterzhou 已提交
472
isAfter(on: On): On
E
add doc  
ester.zhou 已提交
473

E
ester.zhou 已提交
474
Specifies that the target component is located after the given attribute component.
E
add doc  
ester.zhou 已提交
475 476 477 478 479

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
480 481
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
E
ester.zhou 已提交
482
| on     | [On](#on9) | Yes  | Information about the attribute component.|
E
add doc  
ester.zhou 已提交
483 484 485

**Return value**

E
esterzhou 已提交
486 487 488
| Type      | Description                                                |
| ---------- | ---------------------------------------------------- |
| [On](#on9) | **On** object.|
E
add doc  
ester.zhou 已提交
489 490 491

**Example**

E
ester.zhou 已提交
492
```js
E
ester.zhou 已提交
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
let on = ON.isAfter(ON.text('123')); // Create an On object using the static constructor ON, specifying that the target component is located after the given attribute component.
```

### within<sup>10+</sup>

within(on: On): On

Specifies that the target component is located within the given attribute component.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Information about the attribute component.|

**Return value**

| Type      | Description                                              |
| ---------- | -------------------------------------------------- |
| [On](#on9) | **On** object.|

**Example**

```js
let on = ON.within(ON.type('List')); // Create an On object using the static constructor ON, specifying that the target component is located within the given attribute component.
```

### inWindow<sup>10+</sup>

inWindow(bundleName: string): On;

Specifies that the target component is within the given application window.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name    | Type  | Mandatory| Description            |
| ---------- | ------ | ---- | ---------------- |
| bundleName | string | Yes  | Bundle name of the application window.|

**Return value**

| Type      | Description                                          |
| ---------- | ---------------------------------------------- |
| [On](#on9) | **On** object.|

**Example**

```js
E
ester.zhou 已提交
545
let on = ON.inWindow('com.uitestScene.acts'); // Create an On object using the static constructor ON, specifying that the target component is within the given application window.
E
add doc  
ester.zhou 已提交
546 547
```

E
esterzhou 已提交
548
## Component<sup>9+</sup>
E
add doc  
ester.zhou 已提交
549

E
esterzhou 已提交
550
In **UiTest** of API version 9, the **Component** class represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection.
E
ester.zhou 已提交
551 552
All APIs provided in this class use a promise to return the result and must be invoked using **await**.

E
esterzhou 已提交
553
### click<sup>9+</sup>
E
add doc  
ester.zhou 已提交
554

E
ester.zhou 已提交
555
click(): Promise\<void>
E
add doc  
ester.zhou 已提交
556 557 558 559 560

Clicks this component.

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
561 562 563 564 565 566 567 568 569
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
570 571
**Example**

E
ester.zhou 已提交
572
```js
E
ester.zhou 已提交
573
async function demo() {
E
esterzhou 已提交
574 575 576
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    await button.click();
E
ester.zhou 已提交
577
}
E
add doc  
ester.zhou 已提交
578 579
```

E
esterzhou 已提交
580
### doubleClick<sup>9+</sup>
E
add doc  
ester.zhou 已提交
581

E
ester.zhou 已提交
582
doubleClick(): Promise\<void>
E
add doc  
ester.zhou 已提交
583 584 585 586 587

Double-clicks this component.

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
588 589 590 591 592 593 594 595 596
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
597 598
**Example**

E
ester.zhou 已提交
599
```js
E
ester.zhou 已提交
600
async function demo() {
E
esterzhou 已提交
601 602 603
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    await button.doubleClick();
E
ester.zhou 已提交
604
}
E
add doc  
ester.zhou 已提交
605 606
```

E
esterzhou 已提交
607
### longClick<sup>9+</sup>
E
add doc  
ester.zhou 已提交
608

E
ester.zhou 已提交
609
longClick(): Promise\<void>
E
add doc  
ester.zhou 已提交
610 611 612 613 614

Long-clicks this component.

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
615 616 617 618 619 620 621 622 623
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
624 625
**Example**

E
ester.zhou 已提交
626
```js
E
ester.zhou 已提交
627
async function demo() {
E
esterzhou 已提交
628 629 630
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    await button.longClick();
E
ester.zhou 已提交
631
}
E
add doc  
ester.zhou 已提交
632 633
```

E
esterzhou 已提交
634
### getId<sup>9+</sup>
E
add doc  
ester.zhou 已提交
635

E
esterzhou 已提交
636
getId(): Promise\<string>
E
add doc  
ester.zhou 已提交
637 638 639 640 641 642 643

Obtains the ID of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
ester.zhou 已提交
644 645
| Type            | Description                           |
| ---------------- | ------------------------------- |
E
esterzhou 已提交
646
| Promise\<string> | Promise used to return the ID of the component.|
E
add doc  
ester.zhou 已提交
647

E
esterzhou 已提交
648
**Error codes**
E
add doc  
ester.zhou 已提交
649

E
esterzhou 已提交
650
For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
add doc  
ester.zhou 已提交
651

E
esterzhou 已提交
652 653 654 655
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
656 657 658

**Example**

E
ester.zhou 已提交
659
```js
E
ester.zhou 已提交
660
async function demo() {
E
esterzhou 已提交
661 662 663
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let num = await button.getId();
E
ester.zhou 已提交
664
}
E
add doc  
ester.zhou 已提交
665 666
```

E
esterzhou 已提交
667
### getText<sup>9+</sup>
E
add doc  
ester.zhou 已提交
668

E
ester.zhou 已提交
669
getText(): Promise\<string>
E
add doc  
ester.zhou 已提交
670 671 672 673 674 675 676

Obtains the text information of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
ester.zhou 已提交
677 678 679
| Type            | Description                             |
| ---------------- | --------------------------------- |
| Promise\<string> | Promise used to return the text information of the component.|
E
add doc  
ester.zhou 已提交
680

E
esterzhou 已提交
681 682 683 684 685 686 687 688 689
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
690 691
**Example**

E
ester.zhou 已提交
692
```js
E
ester.zhou 已提交
693
async function demo() {
E
esterzhou 已提交
694 695 696
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let text = await button.getText();
E
ester.zhou 已提交
697
}
E
add doc  
ester.zhou 已提交
698 699
```

E
esterzhou 已提交
700
### getType<sup>9+</sup>
E
add doc  
ester.zhou 已提交
701

E
ester.zhou 已提交
702
getType(): Promise\<string>
E
add doc  
ester.zhou 已提交
703 704 705 706 707 708 709

Obtains the type of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
ester.zhou 已提交
710 711 712
| Type            | Description                         |
| ---------------- | ----------------------------- |
| Promise\<string> | Promise used to return the type of the component.|
E
add doc  
ester.zhou 已提交
713

E
esterzhou 已提交
714 715 716 717 718 719 720 721 722
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
723 724
**Example**

E
ester.zhou 已提交
725
```js
E
ester.zhou 已提交
726
async function demo() {
E
esterzhou 已提交
727 728 729
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let type = await button.getType();
E
ester.zhou 已提交
730
}
E
add doc  
ester.zhou 已提交
731 732
```

E
esterzhou 已提交
733
### getBounds<sup>9+</sup>
E
ester.zhou 已提交
734 735 736 737 738 739 740 741 742

getBounds(): Promise\<Rect>

Obtains the bounds of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
| Type                    | Description                                 |
| ------------------------ | ------------------------------------- |
| Promise\<[Rect](#rect9)> | Promise used to return the bounds of the component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let rect = await button.getBounds();
}
```

### getBoundsCenter<sup>9+</sup>

getBoundsCenter(): Promise\<Point>

Obtains the information about the center of the bounding box around this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                      | Description                                           |
| -------------------------- | ----------------------------------------------- |
| Promise\<[Point](#point9)> | Promise used to return the information about the center of the bounding box around the component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
788 789 790 791 792

**Example**

```js
async function demo() {
E
esterzhou 已提交
793 794 795
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let point = await button.getBoundsCenter();
E
ester.zhou 已提交
796 797 798
}
```

E
esterzhou 已提交
799
### isClickable<sup>9+</sup>
E
add doc  
ester.zhou 已提交
800

E
esterzhou 已提交
801
isClickable(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
802 803 804 805 806 807 808

Obtains the clickable status of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
809 810 811 812 813 814 815 816 817 818 819 820
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is clickable, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
821 822 823

**Example**

E
ester.zhou 已提交
824
```js
E
ester.zhou 已提交
825
async function demo() {
E
esterzhou 已提交
826 827
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
828
    if(await button.isClickable()) {
E
esterzhou 已提交
829 830 831
        console.info('This button can be Clicked');
    } else {
        console.info('This button can not be Clicked');
E
ester.zhou 已提交
832 833
    }
}
E
add doc  
ester.zhou 已提交
834 835
```

E
esterzhou 已提交
836
### isLongClickable<sup>9+</sup>
E
add doc  
ester.zhou 已提交
837

E
esterzhou 已提交
838
isLongClickable(): Promise\<boolean> 
E
add doc  
ester.zhou 已提交
839

E
esterzhou 已提交
840
Obtains the long-clickable status of this component.
E
ester.zhou 已提交
841 842 843 844 845

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
846 847 848 849 850 851 852 853 854 855 856 857
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the long-clickable status of the component. The value **true** means that the component is long-clickable, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
858 859 860 861 862

**Example**

```js
async function demo() {
E
esterzhou 已提交
863 864
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
865
    if(await button.isLongClickable()) {
E
esterzhou 已提交
866 867 868
        console.info('This button can longClick');
    } else {
        console.info('This button can not longClick');
E
ester.zhou 已提交
869 870 871 872
    }
}
```

E
esterzhou 已提交
873
### isChecked<sup>9+</sup>
E
ester.zhou 已提交
874

E
esterzhou 已提交
875
isChecked(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
876

E
ester.zhou 已提交
877
Obtains the checked status of this component.
E
add doc  
ester.zhou 已提交
878 879 880 881 882

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
883 884 885 886 887 888 889 890 891 892 893 894
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the checked status of the component. The value **true** means that the component is checked, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
895 896 897

**Example**

E
ester.zhou 已提交
898 899
```js
async function demo() {
E
esterzhou 已提交
900 901
    let driver = Driver.create();
    let checkBox = await driver.findComponent(ON.type('Checkbox'));
E
ester.zhou 已提交
902
    if(await checkBox.isChecked) {
E
esterzhou 已提交
903 904 905
        console.info('This checkBox is checked');
    } else {
        console.info('This checkBox is not checked');
E
ester.zhou 已提交
906 907
    }
}
E
add doc  
ester.zhou 已提交
908
```
E
ester.zhou 已提交
909

E
esterzhou 已提交
910
### isCheckable<sup>9+</sup>
E
ester.zhou 已提交
911

E
esterzhou 已提交
912
isCheckable(): Promise\<boolean>
E
ester.zhou 已提交
913

E
esterzhou 已提交
914
Obtains the checkable status of this component.
E
ester.zhou 已提交
915 916 917 918 919

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
920 921 922 923 924 925 926 927 928 929 930 931
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the checkable status of the component. The value **true** means that the component is checkable, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
932 933 934 935 936

**Example**

```js
async function demo() {
E
esterzhou 已提交
937 938
    let driver = Driver.create();
    let checkBox = await driver.findComponent(ON.type('Checkbox'));
E
ester.zhou 已提交
939
    if(await checkBox.isCheckable) {
E
esterzhou 已提交
940 941 942
        console.info('This checkBox is checkable');
    } else {
        console.info('This checkBox is not checkable');
E
ester.zhou 已提交
943 944 945 946
    }
}
```

E
esterzhou 已提交
947
### isScrollable<sup>9+</sup>
E
ester.zhou 已提交
948

E
esterzhou 已提交
949
isScrollable(): Promise\<boolean>
E
ester.zhou 已提交
950 951 952 953 954 955 956

Obtains the scrollable status of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
957 958 959 960 961 962 963 964 965 966 967 968
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is scrollable, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
969 970 971 972

**Example**

```js
E
ester.zhou 已提交
973
async function demo() {
E
esterzhou 已提交
974 975
    let driver = Driver.create();
    let scrollBar = await driver.findComponent(ON.scrollable(true));
E
ester.zhou 已提交
976
    if(await scrollBar.isScrollable()) {
E
esterzhou 已提交
977 978 979
        console.info('This scrollBar can be operated');
    } else {
        console.info('This scrollBar can not be operated');
E
ester.zhou 已提交
980 981
    }
}
E
add doc  
ester.zhou 已提交
982 983 984
```


E
esterzhou 已提交
985
### isEnabled<sup>9+</sup>
E
add doc  
ester.zhou 已提交
986

E
esterzhou 已提交
987
isEnabled(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
988

E
ester.zhou 已提交
989
Obtains the enabled status of this component.
E
add doc  
ester.zhou 已提交
990 991 992 993 994

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
| Type             | Description                                                      |
| ----------------- | ---------------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is enabled, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1007 1008 1009

**Example**

E
ester.zhou 已提交
1010
```js
E
ester.zhou 已提交
1011
async function demo() {
E
esterzhou 已提交
1012 1013
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
1014
    if(await button.isEnabled()) {
E
esterzhou 已提交
1015 1016 1017
        console.info('This button can be operated');
    } else {
        console.info('This button can not be operated');
E
ester.zhou 已提交
1018 1019 1020
    }
}

E
add doc  
ester.zhou 已提交
1021 1022
```

E
esterzhou 已提交
1023
### isFocused<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1024

E
esterzhou 已提交
1025
isFocused(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
1026 1027 1028 1029 1030 1031 1032

Obtains the focused status of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the focused status of the component. The value **true** means that the component is focused, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1045 1046 1047

**Example**

E
ester.zhou 已提交
1048
```js
E
ester.zhou 已提交
1049
async function demo() {
E
esterzhou 已提交
1050 1051
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
1052
    if(await button.isFocused()) {
E
esterzhou 已提交
1053 1054 1055
        console.info('This button is focused');
    } else {
        console.info('This button is not focused');
E
ester.zhou 已提交
1056 1057
	}
}
E
add doc  
ester.zhou 已提交
1058 1059
```

E
esterzhou 已提交
1060
### isSelected<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1061

E
esterzhou 已提交
1062
isSelected(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
1063 1064 1065 1066 1067 1068 1069

Obtains the selected status of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
| Type             | Description                                               |
| ----------------- | --------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is selected, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1082 1083 1084

**Example**

E
ester.zhou 已提交
1085
```js
E
ester.zhou 已提交
1086
async function demo() {
E
esterzhou 已提交
1087 1088
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
1089
    if(await button.isSelected()) {
E
esterzhou 已提交
1090 1091 1092
        console.info('This button is selected');
	} else {
        console.info('This button is not selected');
E
ester.zhou 已提交
1093 1094
    }
}
E
add doc  
ester.zhou 已提交
1095 1096
```

E
esterzhou 已提交
1097
### inputText<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1098

E
ester.zhou 已提交
1099
inputText(text: string): Promise\<void>
E
add doc  
ester.zhou 已提交
1100 1101 1102 1103 1104 1105 1106

Enters text into this component (available for text boxes).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
| Name| Type  | Mandatory| Description                                    |
| ------ | ------ | ---- | ---------------------------------------- |
| text   | string | Yes  | Text to enter, which can contain English and special characters.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1119 1120 1121

**Example**

E
ester.zhou 已提交
1122 1123
```js
async function demo() {
E
esterzhou 已提交
1124 1125 1126
    let driver = Driver.create();
    let text = await driver.findComponent(ON.text('hello world'));
    await text.inputText('123');
E
ester.zhou 已提交
1127
}
E
add doc  
ester.zhou 已提交
1128
```
E
ester.zhou 已提交
1129

E
esterzhou 已提交
1130
### clearText<sup>9+</sup>
E
ester.zhou 已提交
1131 1132 1133

clearText(): Promise\<void>

E
esterzhou 已提交
1134
Clears text in this component. This API is applicable to text boxes.
E
ester.zhou 已提交
1135 1136 1137

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
1138 1139 1140 1141 1142 1143 1144
**Error codes**

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
ester.zhou 已提交
1145 1146 1147
**Example**

```js
E
ester.zhou 已提交
1148
async function demo() {
E
esterzhou 已提交
1149 1150 1151
    let driver = Driver.create();
    let text = await driver.findComponent(ON.text('hello world'));
    await text.clearText();
E
ester.zhou 已提交
1152
}
E
add doc  
ester.zhou 已提交
1153 1154
```

E
esterzhou 已提交
1155
### scrollSearch<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1156

E
esterzhou 已提交
1157
scrollSearch(on: On): Promise\<Component>
E
add doc  
ester.zhou 已提交
1158

E
esterzhou 已提交
1159
Scrolls on this component to search for the target component. This API is applicable to components that support scrolling.
E
add doc  
ester.zhou 已提交
1160 1161 1162 1163 1164

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1165 1166 1167
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the target component.|
E
add doc  
ester.zhou 已提交
1168 1169 1170

**Return value**

E
esterzhou 已提交
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
| Type                              | Description                                 |
| ---------------------------------- | ------------------------------------- |
| Promise\<[Component](#component9)> | Promise used to return the target component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1183 1184 1185

**Example**

E
ester.zhou 已提交
1186
```js
E
ester.zhou 已提交
1187
async function demo() {
E
esterzhou 已提交
1188 1189 1190
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('Scroll'));
    let button = await scrollBar.scrollSearch(ON.text('next page'));
E
ester.zhou 已提交
1191
}
E
add doc  
ester.zhou 已提交
1192 1193
```

E
esterzhou 已提交
1194
### scrollToTop<sup>9+</sup>
E
ester.zhou 已提交
1195

E
esterzhou 已提交
1196
scrollToTop(speed?: number): Promise\<void>
E
ester.zhou 已提交
1197

E
esterzhou 已提交
1198
Scrolls to the top of this component. This API is applicable to components that support scrolling.
E
ester.zhou 已提交
1199 1200 1201

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216
**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
ester.zhou 已提交
1217 1218 1219 1220
**Example**

```js
async function demo() {
E
esterzhou 已提交
1221 1222 1223
    let driver = Driver.create();
    let scrollBar = await driver.findComponent(ON.type('Scroll'));
    await scrollBar.scrollToTop();
E
ester.zhou 已提交
1224 1225 1226
}
```

E
esterzhou 已提交
1227
### scrollToBottom<sup>9+</sup>
E
ester.zhou 已提交
1228

E
esterzhou 已提交
1229
scrollToBottom(speed?: number): Promise\<void>
E
ester.zhou 已提交
1230

E
esterzhou 已提交
1231
Scrolls to the bottom of this component. This API is applicable to components that support scrolling.
E
ester.zhou 已提交
1232 1233 1234

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
ester.zhou 已提交
1250 1251 1252 1253
**Example**

```js
async function demo() {
E
esterzhou 已提交
1254 1255 1256
    let driver = Driver.create();
    let scrollBar = await driver.findComponent(ON.type('Scroll'));
    await scrollBar.scrollToBottom();
E
ester.zhou 已提交
1257 1258 1259
}
```

E
esterzhou 已提交
1260
### dragTo<sup>9+</sup>
E
ester.zhou 已提交
1261

E
esterzhou 已提交
1262
dragTo(target: Component): Promise\<void>
E
ester.zhou 已提交
1263 1264 1265 1266 1267 1268 1269

Drags this component to the target component.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
| Name| Type                    | Mandatory| Description      |
| ------ | ------------------------ | ---- | ---------- |
| target | [Component](#component9) | Yes  | Target component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
1282 1283 1284 1285 1286

**Example**

```js
async function demo() {
E
esterzhou 已提交
1287 1288 1289 1290
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let text = await driver.findComponent(ON.text('hello world'));
    await button.dragTo(text);
E
ester.zhou 已提交
1291 1292 1293
    }
```

E
esterzhou 已提交
1294
### pinchOut<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1295

E
esterzhou 已提交
1296
pinchOut(scale: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1297

E
esterzhou 已提交
1298
Pinches a component to scale it up to the specified ratio.
E
add doc  
ester.zhou 已提交
1299

E
esterzhou 已提交
1300
**System capability**: SystemCapability.Test.UiTest
E
add doc  
ester.zhou 已提交
1301

E
esterzhou 已提交
1302
**Parameters**
E
add doc  
ester.zhou 已提交
1303

E
esterzhou 已提交
1304 1305 1306
| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| scale  | number | Yes  | Scale factor.|
E
add doc  
ester.zhou 已提交
1307

E
esterzhou 已提交
1308 1309 1310
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
add doc  
ester.zhou 已提交
1311

E
esterzhou 已提交
1312 1313 1314 1315
| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1316 1317 1318

**Example**

E
ester.zhou 已提交
1319
```js
E
ester.zhou 已提交
1320
async function demo() {
E
esterzhou 已提交
1321 1322 1323 1324
    let driver = Driver.create();
    let image = await driver.findComponent(ON.type('image'));
    await image.pinchOut(1.5);
    }
E
add doc  
ester.zhou 已提交
1325 1326
```

E
esterzhou 已提交
1327
### pinchIn<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1328

E
esterzhou 已提交
1329
pinchIn(scale: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1330

E
esterzhou 已提交
1331
Pinches a component to scale it down to the specified ratio.
E
add doc  
ester.zhou 已提交
1332 1333 1334 1335 1336

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| scale  | number | Yes  | Scale factor.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1349 1350 1351

**Example**

E
ester.zhou 已提交
1352
```js
E
ester.zhou 已提交
1353
async function demo() {
E
esterzhou 已提交
1354 1355 1356 1357
    let driver = Driver.create();
    let image = await driver.findComponent(ON.type('image'));
    await image.pinchIn(0.5);
    }
E
add doc  
ester.zhou 已提交
1358 1359
```

E
esterzhou 已提交
1360
## Driver<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1361

E
esterzhou 已提交
1362 1363
The **Driver** class is the main entry to the UiTest framework. It provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot.
All APIs provided by this class, except for **Driver.create()**, use a promise to return the result and must be invoked using **await**.
E
add doc  
ester.zhou 已提交
1364

E
esterzhou 已提交
1365
### create<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1366

E
esterzhou 已提交
1367
static create(): Driver
E
add doc  
ester.zhou 已提交
1368

E
esterzhou 已提交
1369
Creates a **Driver** object and returns the object created. This API is a static API.
E
add doc  
ester.zhou 已提交
1370

E
esterzhou 已提交
1371
**System capability**: SystemCapability.Test.UiTest
E
add doc  
ester.zhou 已提交
1372 1373 1374

**Return value**

E
esterzhou 已提交
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
| Type| Description          |
| -------- | ---------------------- |
| Driver   | **Driver** object created.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message          |
| -------- | ------------------ |
| 17000001 | Initialize failed. |
E
add doc  
ester.zhou 已提交
1386 1387 1388

**Example**

E
ester.zhou 已提交
1389
```js
E
ester.zhou 已提交
1390
async function demo() {
E
esterzhou 已提交
1391
    let driver = Driver.create();
E
ester.zhou 已提交
1392
}
E
add doc  
ester.zhou 已提交
1393 1394
```

E
esterzhou 已提交
1395
### delayMs<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1396

E
esterzhou 已提交
1397
delayMs(duration: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1398

E
esterzhou 已提交
1399
Delays this **Driver** object within the specified duration.
E
add doc  
ester.zhou 已提交
1400 1401 1402 1403 1404

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1405 1406 1407
| Name  | Type  | Mandatory| Description                  |
| -------- | ------ | ---- | ---------------------- |
| duration | number | Yes  | Duration of time, in ms.|
E
add doc  
ester.zhou 已提交
1408

E
esterzhou 已提交
1409 1410 1411
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
add doc  
ester.zhou 已提交
1412

E
esterzhou 已提交
1413 1414 1415
| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1416 1417 1418

**Example**

E
ester.zhou 已提交
1419
```js
E
ester.zhou 已提交
1420
async function demo() {
E
esterzhou 已提交
1421 1422
    let driver = Driver.create();
    await driver.delayMs(1000);
E
ester.zhou 已提交
1423
}
E
add doc  
ester.zhou 已提交
1424 1425
```

E
esterzhou 已提交
1426
### findComponent<sup>9+</sup>
E
ester.zhou 已提交
1427

E
esterzhou 已提交
1428
findComponent(on: On): Promise\<Component>
E
ester.zhou 已提交
1429

E
esterzhou 已提交
1430
Searches this **Driver** object for the target component that matches the given attributes.
E
ester.zhou 已提交
1431 1432 1433 1434 1435

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1436 1437 1438
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the target component.|
E
ester.zhou 已提交
1439 1440 1441

**Return value**

E
esterzhou 已提交
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452
| Type                              | Description                             |
| ---------------------------------- | --------------------------------- |
| Promise\<[Component](#component9)> | Promise used to return the found component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
ester.zhou 已提交
1453 1454 1455 1456 1457

**Example**

```js
async function demo() {
E
esterzhou 已提交
1458 1459
    let driver = Driver.create();
    let button = await driver.findComponent(ON.text('next page'));
E
ester.zhou 已提交
1460 1461 1462
}
```

E
esterzhou 已提交
1463
### findComponents<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1464

E
esterzhou 已提交
1465
findComponents(on: On): Promise\<Array\<Component>>
E
add doc  
ester.zhou 已提交
1466

E
esterzhou 已提交
1467
Searches this **Driver** object for all components that match the given attributes.
E
add doc  
ester.zhou 已提交
1468 1469 1470 1471 1472

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1473 1474 1475
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the target component.|
E
add doc  
ester.zhou 已提交
1476

E
esterzhou 已提交
1477
**Return value**
E
add doc  
ester.zhou 已提交
1478

E
esterzhou 已提交
1479 1480 1481
| Type                                      | Description                                   |
| ------------------------------------------ | --------------------------------------- |
| Promise\<Array\<[Component](#component9)>> | Promise used to return a list of found components.|
E
add doc  
ester.zhou 已提交
1482

E
esterzhou 已提交
1483
**Error codes**
E
add doc  
ester.zhou 已提交
1484

E
esterzhou 已提交
1485
For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
add doc  
ester.zhou 已提交
1486

E
esterzhou 已提交
1487 1488 1489
| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1490 1491 1492

**Example**

E
ester.zhou 已提交
1493
```js
E
ester.zhou 已提交
1494
async function demo() {
E
esterzhou 已提交
1495 1496
    let driver = Driver.create();
    let buttonList = await driver.findComponents(ON.text('next page'));
E
ester.zhou 已提交
1497
}
E
add doc  
ester.zhou 已提交
1498 1499
```

E
esterzhou 已提交
1500
### findWindow<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1501

E
esterzhou 已提交
1502
findWindow(filter: WindowFilter): Promise\<UiWindow>
E
add doc  
ester.zhou 已提交
1503

E
esterzhou 已提交
1504
Searches for the window that matches the specified attributes.
E
add doc  
ester.zhou 已提交
1505 1506 1507 1508 1509

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
| Name| Type                          | Mandatory| Description            |
| ------ | ------------------------------ | ---- | ---------------- |
| filter | [WindowFilter](#windowfilter9) | Yes  | Attributes of the target window.|

**Return value**

| Type                            | Description                                 |
| -------------------------------- | ------------------------------------- |
| Promise\<[UiWindow](#uiwindow9)> | Promise used to return the target window.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1527 1528 1529

**Example**

E
ester.zhou 已提交
1530
```js
E
ester.zhou 已提交
1531
async function demo() {
E
esterzhou 已提交
1532 1533
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
E
ester.zhou 已提交
1534
}
E
add doc  
ester.zhou 已提交
1535 1536
```

E
esterzhou 已提交
1537
### waitForComponent<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1538

E
esterzhou 已提交
1539
waitForComponent(on: On, time: number): Promise\<Component>
E
add doc  
ester.zhou 已提交
1540

E
esterzhou 已提交
1541
Searches this **Driver** object for the target component that matches the given attributes within the specified duration.
E
add doc  
ester.zhou 已提交
1542 1543 1544 1545 1546

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1547 1548 1549 1550 1551 1552 1553 1554 1555
| Name| Type      | Mandatory| Description                            |
| ------ | ---------- | ---- | -------------------------------- |
| On     | [On](#on9) | Yes  | Attributes of the target component.            |
| time   | number     | Yes  | Duration for searching for the target component, in ms.|

**Return value**

| Type                             | Description                             |
| --------------------------------- | --------------------------------- |
E
ester.zhou 已提交
1556
| Promise\<[Component](#component9)> | Promise used to return the found component.|
E
esterzhou 已提交
1557 1558 1559 1560 1561 1562 1563 1564

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1565 1566 1567

**Example**

E
ester.zhou 已提交
1568
```js
E
ester.zhou 已提交
1569
async function demo() {
E
esterzhou 已提交
1570 1571
    let driver = Driver.create();
    let button = await driver.waitForComponent(ON.text('next page'),500);
E
ester.zhou 已提交
1572
}
E
add doc  
ester.zhou 已提交
1573 1574
```

E
esterzhou 已提交
1575
### assertComponentExist<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1576

E
esterzhou 已提交
1577
assertComponentExist(on: On): Promise\<void>
E
add doc  
ester.zhou 已提交
1578

E
esterzhou 已提交
1579
Asserts that a component that matches the given attributes exists on the current page.
E
add doc  
ester.zhou 已提交
1580 1581 1582 1583 1584

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1585 1586 1587
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the target component.|
E
add doc  
ester.zhou 已提交
1588

E
esterzhou 已提交
1589
**Error codes**
E
add doc  
ester.zhou 已提交
1590

E
esterzhou 已提交
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600
For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000003 | Component existence assertion failed.    |

**Example**

```js
E
ester.zhou 已提交
1601
async function demo() {
E
esterzhou 已提交
1602 1603
    let driver = Driver.create();
    await driver.assertComponentExist(ON.text('next page'));
E
ester.zhou 已提交
1604
}
E
add doc  
ester.zhou 已提交
1605 1606
```

E
esterzhou 已提交
1607
### pressBack<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1608

E
esterzhou 已提交
1609
pressBack(): Promise\<void>
E
add doc  
ester.zhou 已提交
1610

E
esterzhou 已提交
1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701
Presses the Back button on this **Driver** object.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.pressBack();
}
```

### triggerKey<sup>9+</sup>

triggerKey(keyCode: number): Promise\<void>

Triggers the key of this **Driver** object that matches the given key code.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type  | Mandatory| Description         |
| ------- | ------ | ---- | ------------- |
| keyCode | number | Yes  | Key code.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.triggerKey(123);
}
```

### triggerCombineKeys<sup>9+</sup>

triggerCombineKeys(key0: number, key1: number, key2?: number): Promise\<void>

Triggers a key combination based on the specified key values. For example, if the value of **Key** is (2072, 2019), the **Driver** object finds and clicks the key combination that matches the value, for example, **Ctrl+C**.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description               |
| ------ | ------ | ---- | ------------------- |
| key0   | number | Yes  | The first key value.|
| key1   | number | Yes  | The second key value.|
| key2   | number | No  | The third key value.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.triggerCombineKeys(2072, 2047, 2035);
}
```


### click<sup>9+</sup>

click(x: number, y: number): Promise\<void>

Clicks a specific point of this **Driver** object based on the given coordinates.
E
add doc  
ester.zhou 已提交
1702 1703 1704 1705 1706

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
1707 1708
| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
E
esterzhou 已提交
1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1719 1720 1721

**Example**

E
ester.zhou 已提交
1722
```js
E
ester.zhou 已提交
1723
async function demo() {
E
esterzhou 已提交
1724 1725
    let driver = Driver.create();
    await driver.click(100,100);
E
ester.zhou 已提交
1726
}
E
add doc  
ester.zhou 已提交
1727 1728
```

E
esterzhou 已提交
1729
### doubleClick<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1730

E
esterzhou 已提交
1731
doubleClick(x: number, y: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1732

E
esterzhou 已提交
1733
Double-clicks a specific point of this **Driver** object based on the given coordinates.
E
add doc  
ester.zhou 已提交
1734 1735 1736 1737 1738

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
1739 1740
| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
E
esterzhou 已提交
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1751 1752 1753

**Example**

E
ester.zhou 已提交
1754
```js
E
ester.zhou 已提交
1755
async function demo() {
E
esterzhou 已提交
1756 1757
    let driver = Driver.create();
    await driver.doubleClick(100,100);
E
ester.zhou 已提交
1758
}
E
add doc  
ester.zhou 已提交
1759 1760
```

E
esterzhou 已提交
1761
### longClick<sup>9+</sup>
E
ester.zhou 已提交
1762

E
esterzhou 已提交
1763
longClick(x: number, y: number): Promise\<void>
E
ester.zhou 已提交
1764

E
esterzhou 已提交
1765
Long-clicks a specific point of this **Driver** object based on the given coordinates.
E
ester.zhou 已提交
1766 1767 1768 1769 1770 1771 1772

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
E
esterzhou 已提交
1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
ester.zhou 已提交
1783 1784 1785 1786 1787

**Example**

```js
async function demo() {
E
esterzhou 已提交
1788 1789
    let driver = Driver.create();
    await driver.longClick(100,100);
E
ester.zhou 已提交
1790 1791 1792
}
```

E
esterzhou 已提交
1793
### swipe<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1794

E
esterzhou 已提交
1795
swipe(startx: number, starty: number, endx: number, endy: number, speed?: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1796

E
esterzhou 已提交
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867
Swipes on this **Driver** object from the given start point to the given end point.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| startx | number | Yes  | X-coordinate of the start point.                      |
| starty | number | Yes  | Y-coordinate of the start point.                      |
| endx   | number | Yes  | X-coordinate of the end point.                      |
| endy   | number | Yes  | Y-coordinate of the end point.                      |
| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.swipe(100,100,200,200,600);
}
```

### drag<sup>9+</sup>

drag(startx: number, starty: number, endx: number, endy: number, speed?: number): Promise\<void>

Drags this **Driver** object from the given start point to the given end point.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| startx | number | Yes  | X-coordinate of the start point.                      |
| starty | number | Yes  | Y-coordinate of the start point.                      |
| endx   | number | Yes  | X-coordinate of the end point.                      |
| endy   | number | Yes  | Y-coordinate of the end point.                      |
| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.drag(100,100,200,200,600);
}
```

### screenCap<sup>9+</sup>

screenCap(savePath: string): Promise\<boolean>

Captures the current screen of this **Driver** object and saves it as a PNG image to the given save path.
E
add doc  
ester.zhou 已提交
1868 1869 1870 1871 1872

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
1873 1874
| Name  | Type  | Mandatory| Description          |
| -------- | ------ | ---- | -------------- |
E
add doc  
ester.zhou 已提交
1875 1876
| savePath | string | Yes  | File save path.|

E
ester.zhou 已提交
1877 1878
**Return value**

E
esterzhou 已提交
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889
| Type             | Description                                  |
| ----------------- | -------------------------------------- |
| Promise\<boolean> | Promise used to return the operation result. The value **true** means that the operation is successful.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
ester.zhou 已提交
1890

E
add doc  
ester.zhou 已提交
1891 1892
**Example**

E
ester.zhou 已提交
1893
```js
E
ester.zhou 已提交
1894
async function demo() {
E
esterzhou 已提交
1895
    let driver = Driver.create();
E
ester.zhou 已提交
1896
    await driver.screenCap('/data/storage/el2/base/cache/1.png');
E
ester.zhou 已提交
1897
}
E
add doc  
ester.zhou 已提交
1898
```
E
ester.zhou 已提交
1899

E
esterzhou 已提交
1900
### setDisplayRotation<sup>9+</sup>
E
ester.zhou 已提交
1901

E
esterzhou 已提交
1902 1903 1904
setDisplayRotation(rotation: DisplayRotation): Promise\<void>

Sets the display rotation of the device.
E
ester.zhou 已提交
1905 1906 1907

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
1908 1909 1910 1911 1912 1913 1914 1915 1916
**Parameters**

| Name  | Type                                | Mandatory| Description            |
| -------- | ------------------------------------ | ---- | ---------------- |
| rotation | [DisplayRotation](#displayrotation9) | Yes  | Display rotation of the device.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
ester.zhou 已提交
1917

E
esterzhou 已提交
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157
| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.setDisplayRotation(DisplayRotation.ROTATION_180);
}
```

### getDisplayRotation<sup>9+</sup>

getDisplayRotation(): Promise\<DisplayRotation>

Obtains the display rotation of the current device.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                                          | Description                                   |
| ---------------------------------------------- | --------------------------------------- |
| Promise\<[DisplayRotation](#displayrotation9)> | Promise used to return the display rotation of the current device.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let rotation = await driver.getDisplayRotation();
}
```

### setDisplayRotationEnabled<sup>9+</sup>

setDisplayRotationEnabled(enabled: boolean): Promise\<void>

Enables or disables display rotation.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type   | Mandatory| Description                                                   |
| ------- | ------- | ---- | ------------------------------------------------------- |
| enabled | boolean | Yes  | Whether to enable display rotation. The value **true** means to enable display rotation, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.setDisplayRotationEnabled(false);
}
```

### getDisplaySize<sup>9+</sup>

getDisplaySize(): Promise\<Point>

Obtains the display size of the current device.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                      | Description                                   |
| -------------------------- | --------------------------------------- |
| Promise\<[Point](#point9)> | Promise used to return the display size of the current device.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let size = await driver.getDisplaySize();
}
```

### getDisplayDensity<sup>9+</sup>

getDisplayDensity(): Promise\<Point>

Obtains the display density of the current device.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                      | Description                                     |
| -------------------------- | ----------------------------------------- |
| Promise\<[Point](#point9)> | Promise used to return the display density of the current device.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let density = await driver.getDisplayDensity();
}
```

### wakeUpDisplay<sup>9+</sup>

wakeUpDisplay(): Promise\<void>

Wakes up the device display.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.wakeUpDisplay();
}
```

### pressHome<sup>9+</sup>

pressHome(): Promise\<void>

Returns to the home screen.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.pressHome();
}
```

### waitForIdle<sup>9+</sup>

waitForIdle(idleTime: number, timeout: number): Promise\<boolean>

Checks whether all components on the current page are idle.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name  | Type  | Mandatory| Description                                                        |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| idleTime | number | Yes  | Idle time threshold, in milliseconds. If the duration for which a component remains inactive reaches this threshold, it is considered as idle.|
| timeout  | number | Yes  | Maximum idle waiting time, in milliseconds.                            |

**Return value**

| Type             | Description                                               |
| ----------------- | --------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let idled = await driver.waitForIdle(4000,5000);
}
```

### fling<sup>9+</sup>

fling(from: Point, to: Point, stepLen: number, speed: number): Promise\<void>

Simulates a fling operation on the screen.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type            | Mandatory| Description                                                        |
| ------- | ---------------- | ---- | ------------------------------------------------------------ |
| from    | [Point](#point9) | Yes  | Coordinates of the point where the finger touches the screen.                                  |
| to      | [Point](#point9) | Yes  | Coordinates of the point where the finger leaves the screen.                                    |
| stepLen | number           | Yes  | Fling step length, in pixels.                                    |
E
ester.zhou 已提交
2158
| speed   | number           | Yes  | Fling speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
E
esterzhou 已提交
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
E
ester.zhou 已提交
2173
    await driver.fling({x: 500, y: 480},{x: 450, y: 480},5,600);
E
esterzhou 已提交
2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211
}
```

### injectMultiPointerAction<sup>9+</sup>

injectMultiPointerAction(pointers: PointerMatrix, speed?: number): Promise\<boolean>

Injects a multi-touch operation to the device.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name  | Type                            | Mandatory| Description                                                        |
| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
| pointers | [PointerMatrix](#pointermatrix9) | Yes  | Scroll trajectory, including the number of fingers and an array of coordinates along the trajectory.                  |
| speed    | number                           | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Return value**

| Type             | Description                                 |
| ----------------- | ------------------------------------- |
| Promise\<boolean> | Promise used to return the result.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let pointers = PointerMatrix.create(2,3);
E
ester.zhou 已提交
2212 2213 2214 2215 2216 2217
    pointers.setPoint(0,0,{x:230,y:480});
    pointers.setPoint(0,1,{x:250,y:380});
    pointers.setPoint(0,2,{x:270,y:280});
    pointers.setPoint(1,0,{x:230,y:680});
    pointers.setPoint(1,1,{x:240,y:580});
    pointers.setPoint(1,2,{x:250,y:480});
E
esterzhou 已提交
2218 2219 2220 2221
    await driver.injectMultiPointerAction(pointers);
}
```

E
ester.zhou 已提交
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391
### fling<sup>10+</sup>

fling(direction: UiDirection, speed: number): Promise<void>;

Simulates a fling operation on the screen, in the specified direction and speed.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name   | Type                         | Mandatory| Description                                                        |
| --------- | ----------------------------- | ---- | ------------------------------------------------------------ |
| direction | [UiDirection](#uidirection10) | Yes  | Direction of the fling operation.                                            |
| speed     | number                        | Yes  | Fling speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.fling(UiDirection.DOWN, 10000);
}
```

### screenCapture<sup>10+</sup>

screenCapture(savePath: string, rect?: Rect): Promise<boolean>;

Captures the specified area of the current screen and saves the captured screenshot as a PNG image to the specified path.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name  | Type          | Mandatory| Description                  |
| -------- | -------------- | ---- | ---------------------- |
| savePath | string         | Yes  | File save path.        |
| rect     | [Rect](#rect9) | No  | Area of the screen to capture. The default value is the entire screen.|

**Return value**

| Type             | Description                                  |
| ----------------- | -------------------------------------- |
| Promise\<boolean> | Promise used to return the operation result. The value **true** means that the operation is successful.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.screenCapture('/data/storage/el2/base/cache/1.png', {left: 0, top: 0, right: 100, bottom: 100});
}
```

### mouseClick<sup>10+</sup>

mouseClick(p: Point, btnId: MouseButton, key1?: number, key2?: number): Promise<void>;

Injects a mouse click at the specified coordinates, with the optional key or key combination. For example, if the value of **key1** is **2072**, the **Ctrl** button is pressed with the mouse click.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type                         | Mandatory| Description               |
| ------ | ----------------------------- | ---- | ------------------- |
| p      | [Point](#point9)              | Yes  | Coordinates of the mouse click.   |
| btnId  | [MouseButton](#mousebutton10) | Yes  | Mouse button pressesd.   |
| key1   | number                        | Yes  | The first key value.|
| key2   | number                        | No  | The second key value.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.mouseClick({x:248, y:194}, MouseButton.MOUSE_BUTTON_LEFT, 2072);
}
```

### mouseScroll<sup>10+</sup>

mouseScroll(p: Point, down: boolean, d: number, key1?: number, key2?: number): Promise<void>;

Injects a mouse scroll action at the specified coordinates, with the optional key or key combination. For example, if the value of **key1** is **2072**, the **Ctrl** button is pressed with mouse scrolling.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type            | Mandatory| Description                                               |
| ------ | ---------------- | ---- | --------------------------------------------------- |
| p      | [Point](#point9) | Yes  | Coordinates of the mouse click.                                   |
| down   | boolean          | Yes  | Whether the scroll wheel slides downward.                             |
| d      | number           | Yes  | Number of grids by which the scroll wheel slides. Sliding by one grid means a 120-pixel offset of the target point.|
| key1   | number           | Yes  | The first key value.                                |
| key2   | number           | No  | The second key value.                                |

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.mouseScroll({x:360, y:640}, true, 30, 2072)
}
```

### mouseMoveTo<sup>10+</sup>

mouseMoveTo(p: Point): Promise<void>;

Moves the cursor to the target point.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type            | Mandatory| Description          |
| ------ | ---------------- | ---- | -------------- |
| p      | [Point](#point9) | Yes  | Coordinates of the target point.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.mouseMoveTo({x:100, y:100})
}
```

E
esterzhou 已提交
2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445
## PointerMatrix<sup>9+</sup>

Implements a **PointerMatrix** object that stores coordinates and behaviors of each action of each finger in a multi-touch operation.

### create<sup>9+</sup>

static create(fingers: number, steps: number): PointerMatrix

Creates a **PointerMatrix** object and returns the object created. This API is a static API.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type  | Mandatory| Description                                      |
| ------- | ------ | ---- | ------------------------------------------ |
| fingers | number | Yes  | Number of fingers in the multi-touch operation. Value range: [1,10].|
| steps   | number | Yes  | Number of steps operated by each finger. Value range: [1,1000].|

**Return value**

| Type                            | Description                         |
| -------------------------------- | ----------------------------- |
| [PointerMatrix](#pointermatrix9) | **PointerMatrix** object created.|

**Example**

```js
async function demo() {
    let pointerMatrix = PointerMatrix.create(2,3);
}
```

### setPoint<sup>9+</sup>

setPoint(finger: number, step: number, point: Point): void

Sets the coordinates for the action corresponding to the specified finger and step in the **PointerMatrix** object.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type            | Mandatory| Description            |
| ------ | ---------------- | ---- | ---------------- |
| finger | number           | Yes  | Sequence number of the finger.    |
| step   | number           | Yes  | Sequence number of the step.    |
| point  | [Point](#point9) | Yes  | Coordinates of the action.|

**Example**

```js
async function demo() {
    let pointers = PointerMatrix.create(2,3);
E
ester.zhou 已提交
2446 2447 2448 2449 2450 2451
    pointers.setPoint(0,0,{x:230,y:480});
    pointers.setPoint(0,1,{x:250,y:380});
    pointers.setPoint(0,2,{x:270,y:280});
    pointers.setPoint(1,0,{x:230,y:680});
    pointers.setPoint(1,1,{x:240,y:580});
    pointers.setPoint(1,2,{x:250,y:480});
E
esterzhou 已提交
2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037
}
```

## UiWindow<sup>9+</sup>

The **UiWindow** class represents a window on the UI and provides APIs for obtaining window attributes, dragging a window, and adjusting the window size.
All APIs provided in this class use a promise to return the result and must be invoked using **await**.

### getBundleName<sup>9+</sup>

getBundleName(): Promise\<string>

Obtains the bundle name of the application to which this window belongs.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                                     |
| ---------------- | ----------------------------------------- |
| Promise\<string> | Promise used to return the bundle name.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let name = await window.getBundleName();
}
```

### getBounds<sup>9+</sup>

getBounds(): Promise\<Rect>

Obtains the bounds information of this window.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                    | Description                             |
| ------------------------ | --------------------------------- |
| Promise\<[Rect](#rect9)> | Promise used to return the bounds information of the window.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let rect = await window.getBounds();
}
```

### getTitle<sup>9+</sup>

getTitle(): Promise\<string>

Obtains the title of this window.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                             |
| ---------------- | --------------------------------- |
| Promise\<string> | Promise used to return the title of the window.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let rect = await window.getTitle();
}
```

### getWindowMode<sup>9+</sup>

getWindowMode(): Promise\<WindowMode>

Obtains the window mode of this window.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                                | Description                                 |
| ------------------------------------ | ------------------------------------- |
| Promise\<[WindowMode](#windowmode9)> | Promise used to return the window mode of the window.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let mode = await window.getWindowMode();
}
```

### isFocused<sup>9+</sup>

isFocused(): Promise\<boolean>

Checks whether this window is in focused state.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the window is in focused state, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let focused = await window.isFocused();
}
```

### isActived<sup>9+</sup>

isActived(): Promise\<boolean>

Checks whether this window is active.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the window is active, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let focused = await window.isActived();
}
```

### focus<sup>9+</sup>

focus(): Promise\<void>

Moves the focus to this window.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.focus();
}
```

### moveTo<sup>9+</sup>

moveTo(x: number, y: number): Promise\<void>

Moves this window to the target point. This API is applicable to moveable windows.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.moveTo(100, 100);
}
```

### resize<sup>9+</sup>

resize(wide: number, height: number, direction: ResizeDirection): Promise\<void>

Resizes this window based on the specified width, height, and resize direction. This API is applicable to resizable windows.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name   | Type                                | Mandatory| Description                                                        |
| --------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| wide      | number                               | Yes  | Target width.                        |
| height    | number                               | Yes  | Target height.                        |
| direction | [ResizeDirection](#resizedirection9) | Yes  | Resize direction.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.resize(100, 100, ResizeDirection.LEFT);
}
```

### split<sup>9+</sup>

split(): Promise\<void>

Switches the window to split-screen mode. This API is applicable to windows that support screen splitting.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.split();
}
```

### maximize<sup>9+</sup>

maximize(): Promise\<void>

Maximizes this window. This API is applicable to windows that can be maximized.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.maximize();
}
```

### minimize<sup>9+</sup>

minimize(): Promise\<void>

Minimizes this window. This API is applicable to windows that can be minimized.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.minimize();
}
```

### resume<sup>9+</sup>

resume(): Promise\<void>

Restores this window to the previous window mode.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.resume();
}
```

### close<sup>9+</sup>

close(): Promise\<void>

Closes this window.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.close();
}
```

## By<sup>(deprecated)</sup>

The UiTest framework provides a wide range of UI component feature description APIs in the **By** class to filter and match components.
The API capabilities provided by the **By** class exhibit the following features: <br>1. Allow one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component. <br>2. Provide multiple match patterns for component attributes. <br>3. Support absolute positioning and relative positioning for components. APIs such as [By.isBefore<sup>(deprecated)</sup>](#isbeforedeprecated) and [By.isAfter<sup>(deprecated)</sup>](#isafterdeprecated) can be used to specify the features of adjacent components to assist positioning. <br>All APIs provided in the **By** class are synchronous. You are advised to use the static constructor **BY** to create a **By** object in chain mode.

This API is deprecated since API version 9. You are advised to use [On<sup>9+</sup>](#on9) instead.

```js
BY.text('123').type('button');
```

### text<sup>(deprecated)</sup>

text(txt: string, pattern?: MatchPattern): By

Specifies the text attribute of the target component. Multiple match patterns are supported.

This API is deprecated since API version 9. You are advised to use [text<sup>9+</sup>](#text9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type                         | Mandatory| Description                                               |
| ------- | ----------------------------- | ---- | --------------------------------------------------- |
| txt     | string                        | Yes  | Component text, used to match the target component.               |
| pattern | [MatchPattern](#matchpattern) | No  | Match pattern. The default value is [EQUALS](#matchpattern).|

**Return value**

| Type               | Description                              |
| ------------------- | ---------------------------------- |
| [By](#bydeprecated) | **By** object that matches the text attribute of the target component.|

**Example**

```js
let by = BY.text('123'); // Use the static constructor BY to create a By object and specify the text attribute of the target component.
```


### key<sup>(deprecated)</sup>

key(key: string): By

Specifies the key attribute of the target component.

This API is deprecated since API version 9. You are advised to use [id<sup>9+</sup>](#id9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description             |
| ------ | ------ | ---- | ----------------- |
| key    | string | Yes  | Component key.|

**Return value**

| Type               | Description                               |
| ------------------- | ----------------------------------- |
| [By](#bydeprecated) | **By** object that matches the key attribute of the target component.|

**Example**

```js
let by = BY.key('123'); // Use the static constructor BY to create a By object and specify the key attribute of the target component.
```


### id<sup>(deprecated)</sup>

id(id: number): By

Specifies the ID attribute of the target component.

This API is deprecated since API version 9.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| id     | number | Yes  | Component ID.|

**Return value**

| Type               | Description                            |
| ------------------- | -------------------------------- |
| [By](#bydeprecated) | **By** object that matches the ID attribute of the target component.|

**Example**

```js
let by = BY.id(123); // Use the static constructor BY to create a By object and specify the ID attribute of the target component.
```


### type<sup>(deprecated)</sup>

type(tp: string): By

Specifies the type attribute of the target component.

This API is deprecated since API version 9. You are advised to use [type<sup>9+</sup>](#type9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description          |
| ------ | ------ | ---- | -------------- |
| tp     | string | Yes  | Component type.|

**Return value**

| Type               | Description                                    |
| ------------------- | ---------------------------------------- |
| [By](#bydeprecated) | **By** object that matches the type attribute of the target component.|

**Example**

```js
let by = BY.type('button'); // Use the static constructor BY to create a By object and specify the type attribute of the target component.
```


### clickable<sup>(deprecated)</sup>

clickable(b?: boolean): By

Specifies the clickable status attribute of the target component.

This API is deprecated since API version 9. You are advised to use [clickable<sup>9+</sup>](#clickable9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
E
ester.zhou 已提交
3038
| b      | boolean | No  | Clickable status of the target component.<br>**true**: clickable.<br>**false**: not clickable.<br>Default value: **true** |
E
esterzhou 已提交
3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066

**Return value**

| Type               | Description                                      |
| ------------------- | ------------------------------------------ |
| [By](#bydeprecated) | **By** object that matches the clickable status attribute of the target component.|

**Example**

```js
let by = BY.clickable(true); // Use the static constructor BY to create a By object and specify the clickable status attribute of the target component.
```


### scrollable<sup>(deprecated)</sup>

scrollable(b?: boolean): By

Specifies the scrollable status attribute of the target component.

This API is deprecated since API version 9. You are advised to use [scrollable<sup>9+</sup>](#scrollable9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                       |
| ------ | ------- | ---- | ----------------------------------------------------------- |
E
ester.zhou 已提交
3067
| b      | boolean | No  | Scrollable status of the target component.<br>**true**: scrollable.<br>**false**: not scrollable.<br>Default value: **true** |
E
esterzhou 已提交
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094

**Return value**

| Type               | Description                                      |
| ------------------- | ------------------------------------------ |
| [By](#bydeprecated) | **By** object that matches the scrollable status attribute of the target component.|

**Example**

```js
let by = BY.scrollable(true); // Use the static constructor BY to create a By object and specify the scrollable status attribute of the target component.
```

### enabled<sup>(deprecated)</sup>

enabled(b?: boolean): By

Specifies the enabled status attribute of the target component.

This API is deprecated since API version 9. You are advised to use [enabled<sup>9+</sup>](#enabled9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                     |
| ------ | ------- | ---- | --------------------------------------------------------- |
E
ester.zhou 已提交
3095
| b      | boolean | No  | Enabled status of the target component.<br>**true**: enabled.<br>**false**: not enabled.<br>Default value: **true** |
E
esterzhou 已提交
3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122

**Return value**

| Type               | Description                                    |
| ------------------- | ---------------------------------------- |
| [By](#bydeprecated) | **By** object that matches the enabled status attribute of the target component.|

**Example**

```js
let by = BY.enabled(true); // Use the static constructor BY to create a By object and specify the enabled status attribute of the target component.
```

### focused<sup>(deprecated)</sup>

focused(b?: boolean): By

Specifies the focused status attribute of the target component.

This API is deprecated since API version 9. You are advised to use [focused<sup>9+</sup>](#focused9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                 |
| ------ | ------- | ---- | ----------------------------------------------------- |
E
ester.zhou 已提交
3123
| b      | boolean | No  | Focused status of the target component.<br>**true**: focused.<br>**false**: not focused.<br>Default value: **true** |
E
esterzhou 已提交
3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150

**Return value**

| Type               | Description                                    |
| ------------------- | ---------------------------------------- |
| [By](#bydeprecated) | **By** object that matches the focused status attribute of the target component.|

**Example**

```js
let by = BY.focused(true); // Use the static constructor BY to create a By object and specify the focused status attribute of the target component.
```

### selected<sup>(deprecated)</sup>

selected(b?: boolean): By

Specifies the selected status of the target component.

This API is deprecated since API version 9. You are advised to use [selected<sup>9+</sup>](#selected9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
E
ester.zhou 已提交
3151
| b      | boolean | No  | Selected status of the target component.<br>**true**: selected.<br>**false**: not selected.<br>Default value: **true** |
E
esterzhou 已提交
3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168

**Return value**

| Type               | Description                                      |
| ------------------- | ------------------------------------------ |
| [By](#bydeprecated) | **By** object that matches the selected status attribute of the target component.|

**Example**

```js
let by = BY.selected(true); // Use the static constructor BY to create a By object and specify the selected status attribute of the target component.
```

### isBefore<sup>(deprecated)</sup>

isBefore(by: By): By

E
ester.zhou 已提交
3169
Specifies that the target component is located before the given attribute component.
E
esterzhou 已提交
3170 3171 3172 3173 3174 3175 3176 3177 3178

This API is deprecated since API version 9. You are advised to use [isBefore<sup>9+</sup>](#isbefore9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description            |
| ------ | ------------------- | ---- | ---------------- |
E
ester.zhou 已提交
3179
| by     | [By](#bydeprecated) | Yes  | Information about the attribute component.|
E
esterzhou 已提交
3180 3181 3182 3183 3184 3185 3186 3187 3188 3189

**Return value**

| Type               | Description                                                |
| ------------------- | ---------------------------------------------------- |
| [By](#bydeprecated) | **By** object.|

**Example**

```js
E
ester.zhou 已提交
3190
let by = BY.isBefore(BY.text('123')); // Use the static constructor BY to create a By object, specifying that the target component is located before the given attribute component.
E
esterzhou 已提交
3191 3192 3193 3194 3195 3196
```

### isAfter<sup>(deprecated)</sup>

isAfter(by: By): By

E
ester.zhou 已提交
3197
Specifies the target component is located after the given attribute component.
E
esterzhou 已提交
3198 3199 3200 3201 3202 3203 3204 3205 3206

This API is deprecated since API version 9. You are advised to use [isAfter<sup>9+</sup>](#isafter9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description            |
| ------ | ------------------- | ---- | ---------------- |
E
ester.zhou 已提交
3207
| by     | [By](#bydeprecated) | Yes  | Information about the attribute component.|
E
esterzhou 已提交
3208 3209 3210 3211 3212 3213 3214 3215 3216 3217

**Return value**

| Type               | Description                                                |
| ------------------- | ---------------------------------------------------- |
| [By](#bydeprecated) | **By** object.|

**Example**

```js
E
ester.zhou 已提交
3218
let by = BY.isAfter(BY.text('123')); // Use the static constructor BY to create a By object, specifying that the target component is located after the given attribute component.
E
esterzhou 已提交
3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922
```

## UiComponent<sup>(deprecated)</sup>

In **UiTest**, the **UiComponent** class represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection.
All APIs provided in this class use a promise to return the result and must be invoked using **await**.

This API is deprecated since API version 9. You are advised to use [Component<sup>9+</sup>](#component9) instead.

### click<sup>(deprecated)</sup>

click(): Promise\<void>

Clicks this component.

This API is deprecated since API version 9. You are advised to use [click<sup>9+</sup>](#click9).

**System capability**: SystemCapability.Test.UiTest

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    await button.click();
}
```

### doubleClick<sup>(deprecated)</sup>

doubleClick(): Promise\<void>

Double-clicks this component.

This API is deprecated since API version 9. You are advised to use [doubleClick<sup>9+</sup>](#doubleclick9).

**System capability**: SystemCapability.Test.UiTest

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    await button.doubleClick();
}
```

### longClick<sup>(deprecated)</sup>

longClick(): Promise\<void>

Long-clicks this component.

This API is deprecated since API version 9. You are advised to use [longClick<sup>9+</sup>](#longclick9).

**System capability**: SystemCapability.Test.UiTest

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    await button.longClick();
}
```

### getId<sup>(deprecated)</sup>

getId(): Promise\<number>

Obtains the ID of this component.

This API is deprecated since API version 9.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                           |
| ---------------- | ------------------------------- |
| Promise\<number> | Promise used to return the ID of the component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let num = await button.getId();
}
```

### getKey<sup>(deprecated)</sup>

getKey(): Promise\<string>

Obtains the key of this component.

This API is deprecated since API version 9. You are advised to use [getId<sup>9+</sup>](#getid9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                          |
| ---------------- | ------------------------------ |
| Promise\<string> | Promise used to return the key of the component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let str_key = await button.getKey();
}
```

### getText<sup>(deprecated)</sup>

getText(): Promise\<string>

Obtains the text information of this component.

This API is deprecated since API version 9. You are advised to use [getText<sup>9+</sup>](#gettext9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                             |
| ---------------- | --------------------------------- |
| Promise\<string> | Promise used to return the text information of the component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let text = await button.getText();
}
```

### getType<sup>(deprecated)</sup>

getType(): Promise\<string>

Obtains the type of this component.

This API is deprecated since API version 9. You are advised to use [getType<sup>9+</sup>](#gettype9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                         |
| ---------------- | ----------------------------- |
| Promise\<string> | Promise used to return the type of the component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let type = await button.getType();
}
```

### isClickable<sup>(deprecated)</sup>

isClickable(): Promise\<boolean>

Obtains the clickable status of this component.

This API is deprecated since API version 9. You are advised to use [isClickable<sup>9+</sup>](#isclickable9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is clickable, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    if(await button.isClickable()) {
        console.info('This button can be Clicked');
    } else {
        console.info('This button can not be Clicked');
    }
}
```

### isScrollable<sup>(deprecated)</sup>

isScrollable(): Promise\<boolean>

Obtains the scrollable status of this component.

This API is deprecated since API version 9. You are advised to use [isScrollable<sup>9+</sup>](#isscrollable9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is scrollable, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let scrollBar = await driver.findComponent(BY.scrollable(true));
    if(await scrollBar.isScrollable()) {
        console.info('This scrollBar can be operated');
    } else {
        console.info('This scrollBar can not be operated');
    }
}
```


### isEnabled<sup>(deprecated)</sup>

isEnabled(): Promise\<boolean>

Obtains the enabled status of this component.

This API is deprecated since API version 9. You are advised to use [isEnabled<sup>9+</sup>](#isenabled9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                      |
| ----------------- | ---------------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is enabled, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    if(await button.isEnabled()) {
        console.info('This button can be operated');
    } else {
        console.info('This button can not be operated');
    }
}

```

### isFocused<sup>(deprecated)</sup>

isFocused(): Promise\<boolean>

Obtains the focused status of this component.

This API is deprecated since API version 9. You are advised to use [isFocused<sup>9+</sup>](#isfocused9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the target component is focused, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    if(await button.isFocused()) {
        console.info('This button is focused');
    } else {
        console.info('This button is not focused');
	}
}
```

### isSelected<sup>(deprecated)</sup>

isSelected(): Promise\<boolean>

Obtains the selected status of this component.

This API is deprecated since API version 9. You are advised to use [isSelected<sup>9+</sup>](#isselected9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                 |
| ----------------- | ----------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is selected, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    if(await button.isSelected()) {
        console.info('This button is selected');
    } else {
        console.info('This button is not selected');
    }
}
```

### inputText<sup>(deprecated)</sup>

inputText(text: string): Promise\<void>

Enters text into this component (available for text boxes).

This API is deprecated since API version 9. You are advised to use [inputText<sup>9+</sup>](#inputtext9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| text   | string | Yes  | Text to enter.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let text = await driver.findComponent(BY.text('hello world'));
    await text.inputText('123');
}
```

### scrollSearch<sup>(deprecated)</sup>

scrollSearch(by: By): Promise\<UiComponent>

Scrolls on this component to search for the target component (applicable to components that support scrolling, such as **\<List>**).

This API is deprecated since API version 9. You are advised to use [scrollSearch<sup>9+</sup>](#scrollsearch9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description                |
| ------ | ------------------- | ---- | -------------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|

**Return value**

| Type                                           | Description                                 |
| ----------------------------------------------- | ------------------------------------- |
| Promise\<[UiComponent](#uicomponentdeprecated)> | Promise used to return the target component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let scrollBar = await driver.findComponent(BY.type('Scroll'));
    let button = await scrollBar.scrollSearch(BY.text('next page'));
}
```

## UiDriver<sup>(deprecated)</sup>

The **UiDriver** class is the main entry to the UiTest framework. It provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot.
All APIs provided by this class, except for **UiDriver.create()**, use a promise to return the result and must be invoked using **await**.

This API is deprecated since API version 9. You are advised to use [Driver<sup>9+</sup>](#driver9) instead.

### create<sup>(deprecated)</sup>

static create(): UiDriver

Creates a **UiDriver** object and returns the object created. This API is a static API.

This API is deprecated since API version 9. You are advised to use [create<sup>9+</sup>](#create9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type    | Description                    |
| -------- | ------------------------ |
| UiDriver | Returns the **UiDriver** object created.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
}
```

### delayMs<sup>(deprecated)</sup>

delayMs(duration: number): Promise\<void>

Delays this **UiDriver** object within the specified duration.

This API is deprecated since API version 9. You are advised to use [delayMs<sup>9+</sup>](#delayms9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name  | Type  | Mandatory| Description        |
| -------- | ------ | ---- | ------------ |
| duration | number | Yes  | Duration of time.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.delayMs(1000);
}
```

### findComponent<sup>(deprecated)</sup>

findComponent(by: By): Promise\<UiComponent>

Searches this **UiDriver** object for the target component that matches the given attributes.

This API is deprecated since API version 9. You are advised to use [findComponent<sup>9+</sup>](#findcomponent9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description                |
| ------ | ------------------- | ---- | -------------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|

**Return value**

| Type                                           | Description                             |
| ----------------------------------------------- | --------------------------------- |
| Promise\<[UiComponent](#uicomponentdeprecated)> | Promise used to return the found component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.text('next page'));
}
```

### findComponents<sup>(deprecated)</sup>

findComponents(by: By): Promise\<Array\<UiComponent>>

Searches this **UiDriver** object for all components that match the given attributes.

This API is deprecated since API version 9. You are advised to use [findComponents<sup>9+</sup>](#findcomponents9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description                |
| ------ | ------------------- | ---- | -------------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|

**Return value**

| Type                                                   | Description                                   |
| ------------------------------------------------------- | --------------------------------------- |
| Promise\<Array\<[UiComponent](#uicomponentdeprecated)>> | Promise used to return a list of found components.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let buttonList = await driver.findComponents(BY.text('next page'));
}
```

### assertComponentExist<sup>(deprecated)</sup>

assertComponentExist(by: By): Promise\<void>

Asserts that a component that matches the given attributes exists on the current page. If the component does not exist, the API throws a JS exception, causing the current test case to fail.

This API is deprecated since API version 9. You are advised to use [assertComponentExist<sup>9+</sup>](#assertcomponentexist9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description                |
| ------ | ------------------- | ---- | -------------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.assertComponentExist(BY.text('next page'));
}
```

### pressBack<sup>(deprecated)</sup>

pressBack(): Promise\<void>

Presses the Back button on this **UiDriver** object.

This API is deprecated since API version 9. You are advised to use [pressBack<sup>9+</sup>](#pressback9).

**System capability**: SystemCapability.Test.UiTest

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.pressBack();
}
```

### triggerKey<sup>(deprecated)</sup>

triggerKey(keyCode: number): Promise\<void>

Triggers the key of this **UiDriver** object that matches the given key code.

This API is deprecated since API version 9. You are advised to use [triggerKey<sup>9+</sup>](#triggerkey9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type  | Mandatory| Description         |
| ------- | ------ | ---- | ------------- |
| keyCode | number | Yes  | Key code.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.triggerKey(123);
}
```


### click<sup>(deprecated)</sup>

click(x: number, y: number): Promise\<void>

Clicks a specific point of this **UiDriver** object based on the given coordinates.

This API is deprecated since API version 9. You are advised to use [click<sup>9+</sup>](#click9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.click(100,100);
}
```

### doubleClick<sup>(deprecated)</sup>

doubleClick(x: number, y: number): Promise\<void>

Double-clicks a specific point of this **UiDriver** object based on the given coordinates.

This API is deprecated since API version 9. You are advised to use [doubleClick<sup>9+</sup>](#doubleclick9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.doubleClick(100,100);
}
```

### longClick<sup>(deprecated)</sup>

longClick(x: number, y: number): Promise\<void>

Long-clicks a specific point of this **UiDriver** object based on the given coordinates.

This API is deprecated since API version 9. You are advised to use [longClick<sup>9+</sup>](#longclick9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.longClick(100,100);
}
```

### swipe<sup>(deprecated)</sup>

swipe(startx: number, starty: number, endx: number, endy: number): Promise\<void>

Swipes on this **UiDriver** object from the start point to the end point based on the given coordinates.

This API is deprecated since API version 9. You are advised to use [swipe<sup>9+</sup>](#swipe9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| startx | number | Yes  | X-coordinate of the start point.|
| starty | number | Yes  | Y-coordinate of the start point.|
| endx   | number | Yes  | X-coordinate of the end point.|
| endy   | number | Yes  | Y-coordinate of the end point.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.swipe(100,100,200,200);
}
```

### screenCap<sup>(deprecated)</sup>

screenCap(savePath: string): Promise\<boolean>

Captures the current screen of this **UiDriver** object and saves it as a PNG image to the given save path.

This API is deprecated since API version 9. You are advised to use [screenCap<sup>9+</sup>](#screencap9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name  | Type  | Mandatory| Description          |
| -------- | ------ | ---- | -------------- |
| savePath | string | Yes  | File save path.|

**Return value**

| Type             | Description                                  |
| ----------------- | -------------------------------------- |
| Promise\<boolean> | Promise used to return the operation result. The value **true** means that the operation is successful.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
E
ester.zhou 已提交
3923
    await driver.screenCap('/data/storage/el2/base/cache/1.png');
E
esterzhou 已提交
3924 3925
}
```