Gestures & keys
Taps, swipes, drags and pinches, plus hardware buttons and the keyboard. Coordinates can be points or 0–1 screen ratios; directional swipes re-randomise the start point, distance, angle and duration every time and follow a hand-like path.
Überblick
- ·The swipe family uses the W3C channel with human-like paths; the drag family uses WDA's native channel for better compatibility
- ·Directional swipes avoid the screen edges by default; pass 'edge' when you want a system edge gesture such as swipe-back
- ·Every duration is in seconds
client.click#
Tap at a coordinate; with a duration it holds for that many seconds before releasing (a long press).
client.click(x: number, y: number, duration?: number): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
x | number | Ja | — | Horizontal position: a 0–1 screen ratio, or points. |
y | number | Ja | — | Vertical position: a 0–1 screen ratio, or points. |
duration | number | Nein | — | Seconds to hold. Omit for a plain tap. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAError | Ratio coordinates were given but the screen size could not be read (the WDA session is unhealthy). |
Hinweise
- When x and y both fall between 0 and 1 they are screen ratios (0.5, 0.5 is the centre); otherwise they are points. The conversion needs the screen size and throws if it cannot be read.
Beispiel
client.click(0.5, 0.5); // 屏幕正中 / screen centre
client.click(200, 640); // point
client.click(0.5, 0.9, 1.2); // 长按 1.2 秒 / long pressSiehe auch client.tapHold、element.click
client.swipe#
Swipe from (x1, y1) to (x2, y2). The end points are exact; the path between them is hand-like — a slight random curve, slow then fast, with small jitter.
client.swipe(x1: number, y1: number, x2: number, y2: number, durationSec?: number): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
x1 | number | Ja | — | Start x. |
y1 | number | Ja | — | Start y. |
x2 | number | Ja | — | End x. |
y2 | number | Ja | — | End y. |
durationSec | number | Nein | 0 | Seconds from the start of the movement to lift-off. 0 picks a random duration based on the distance. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAError | Ratio coordinates were given but the screen size could not be read (the WDA session is unhealthy). |
Hinweise
- When x and y both fall between 0 and 1 they are screen ratios (0.5, 0.5 is the centre); otherwise they are points. The conversion needs the screen size and throws if it cannot be read.
Beispiel
client.swipe(0.5, 0.8, 0.5, 0.2); // 往上滑 / swipe up
client.swipe(0.5, 0.8, 0.5, 0.2, 0.6); // 指定 0.6 秒 / take 0.6 secondsSiehe auch client.swipeUp、client.drag
client.drag#
A native WDA drag from (x1, y1) to (x2, y2). The system generates the path and speed; in some apps (custom-drawn views, older iOS) it is more reliable than swipe.
client.drag(x1: number, y1: number, x2: number, y2: number, durationSec?: number): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
x1 | number | Ja | — | Start x. |
y1 | number | Ja | — | Start y. |
x2 | number | Ja | — | End x. |
y2 | number | Ja | — | End y. |
durationSec | number | Nein | 0 | Seconds to hold the start point before dragging — not the duration of the drag itself. 0 drags immediately. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAError | Ratio coordinates were given but the screen size could not be read (the WDA session is unhealthy). |
Hinweise
- When x and y both fall between 0 and 1 they are screen ratios (0.5, 0.5 is the centre); otherwise they are points. The conversion needs the screen size and throws if it cannot be read.
Beispiel
client.drag(0.2, 0.5, 0.8, 0.5, 0.3);Siehe auch client.swipe、client.dragUp
client.swipeUp#
Move the finger up (content moves up, revealing what is below). The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses the W3C gesture channel with a hand-like path: a slight random curve, slow then fast, with small jitter.
client.swipeUp(from?: "edge"): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
from | "edge" | Nein | — | Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the bottom edge, which is the system's go-home gesture — rarely what you want. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAErrorINVALID_ARGUMENT | The argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }). |
Hinweise
- For the short, quick swipe from the lower screen used to scroll a feed, call client.swipeUpFromBottom(); swipeDownFromBottom, dragUpFromBottom and dragDownFromBottom are also available.
Beispiel
client.swipeUp();Siehe auch client.swipe
client.swipeDown#
Move the finger down (content moves down, revealing what is above). The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses the W3C gesture channel with a hand-like path: a slight random curve, slow then fast, with small jitter.
client.swipeDown(from?: "edge"): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
from | "edge" | Nein | — | Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the top edge, which pulls down Notification Centre. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAErrorINVALID_ARGUMENT | The argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }). |
Beispiel
client.swipeDown();Siehe auch client.swipe
client.swipeLeft#
Move the finger from right to left. The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses the W3C gesture channel with a hand-like path: a slight random curve, slow then fast, with small jitter.
client.swipeLeft(from?: "edge"): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
from | "edge" | Nein | — | Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the right edge. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAErrorINVALID_ARGUMENT | The argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }). |
Beispiel
client.swipeLeft();Siehe auch client.swipe
client.swipeRight#
Move the finger from left to right. The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses the W3C gesture channel with a hand-like path: a slight random curve, slow then fast, with small jitter.
client.swipeRight(from?: "edge"): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
from | "edge" | Nein | — | Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the left edge, which is the system's swipe-back gesture. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAErrorINVALID_ARGUMENT | The argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }). |
Beispiel
client.swipeRight(); // 普通右滑 / a normal swipe
client.swipeRight('edge'); // 返回上一页 / go backSiehe auch client.swipe
client.dragUp#
Move the finger up (content moves up). The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses WDA's native drag channel and holds the start point for a random 0.05–0.2 seconds before moving. Switch to this family when swipe has no effect in an app.
client.dragUp(from?: "edge"): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
from | "edge" | Nein | — | Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the bottom edge. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAErrorINVALID_ARGUMENT | The argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }). |
Beispiel
client.dragUp();Siehe auch client.drag
client.dragDown#
Move the finger down (content moves down). The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses WDA's native drag channel and holds the start point for a random 0.05–0.2 seconds before moving. Switch to this family when swipe has no effect in an app.
client.dragDown(from?: "edge"): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
from | "edge" | Nein | — | Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the top edge. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAErrorINVALID_ARGUMENT | The argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }). |
Beispiel
client.dragDown();Siehe auch client.drag
client.dragLeft#
Move the finger from right to left. The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses WDA's native drag channel and holds the start point for a random 0.05–0.2 seconds before moving. Switch to this family when swipe has no effect in an app.
client.dragLeft(from?: "edge"): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
from | "edge" | Nein | — | Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the right edge. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAErrorINVALID_ARGUMENT | The argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }). |
Beispiel
client.dragLeft();Siehe auch client.drag
client.dragRight#
Move the finger from left to right. The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses WDA's native drag channel and holds the start point for a random 0.05–0.2 seconds before moving. Switch to this family when swipe has no effect in an app.
client.dragRight(from?: "edge"): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
from | "edge" | Nein | — | Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the left edge. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAErrorINVALID_ARGUMENT | The argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }). |
Beispiel
client.dragRight();Siehe auch client.drag
client.scroll#
Let WDA scroll the current screen in a direction. XCUITest computes the amount, which makes it more reliable than a swipe for lists and other scroll views.
client.scroll(direction: "up" | "down" | "left" | "right", distance?: number): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
direction | "up" | "down" | "left" | "right" | Ja | — | The direction to scroll. |
distance | number | Nein | 1.0 | How far to scroll; 1.0 is roughly one screen. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Beispiel
client.scroll('down', 1.0);Siehe auch client.swipeUp
client.pinch#
A two-finger pinch: a scale above 1 spreads the fingers (zoom in), below 1 pinches them together (zoom out).
client.pinch(scale: number, velocity?: number): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
scale | number | Ja | — | The scale factor. |
velocity | number | Nein | 1 | The speed; pass a negative value when pinching in (scale below 1). |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Beispiel
client.pinch(2, 1); // 放大 / zoom in
client.pinch(0.5, -1); // 缩小 / zoom outclient.hideKeyboard#
Dismiss the keyboard; client.isKeyboardShown() tells whether it is up.
client.hideKeyboard(): boolean;
client.isKeyboardShown(): boolean;Rückgabewert
| Typ | Beschreibung |
|---|---|
boolean | hideKeyboard: true once the keyboard is gone (also when it was never up); isKeyboardShown: true while the keyboard is visible. |
Beispiel
if (client.isKeyboardShown()) {
client.hideKeyboard();
}Siehe auch client.sendKeys
client.tapHold#
Press and hold at a point, then release (a long press).
client.tapHold(x: number, y: number, duration?: number): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
x | number | Ja | — | Horizontal position: a 0–1 screen ratio, or points. |
y | number | Ja | — | Vertical position: a 0–1 screen ratio, or points. |
duration | number | Nein | 1.0 | Seconds to hold. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
WDAError | Ratio coordinates were given but the screen size could not be read (the WDA session is unhealthy). |
Hinweise
- When x and y both fall between 0 and 1 they are screen ratios (0.5, 0.5 is the centre); otherwise they are points. The conversion needs the screen size and throws if it cannot be read.
Beispiel
client.tapHold(0.5, 0.5, 1.5);Siehe auch client.click
client.home#
Go to the Home Screen.
client.home(): void;Beispiel
client.home();Siehe auch client.press
client.press#
Press a hardware button: home, volumeUp or volumeDown.
client.press(name: "home" | "volumeUp" | "volumeDown"): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
name | "home" | "volumeUp" | "volumeDown" | Ja | — | The button name. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Ausnahmen
| Ausnahme | Wird ausgelöst, wenn |
|---|---|
Error | The name is not one of the three. |
Beispiel
client.press('volumeUp');Siehe auch client.home
client.sendKeys#
Type into the focused text field, character by character through the keyboard. Tap the field first so it has focus.
client.sendKeys(value: string): object;Parameter
| Name | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
value | string | Ja | — | The text to type; non-ASCII text is supported. |
Rückgabewert
| Typ | Beschreibung |
|---|---|
object | The raw WDA response; rarely needed. |
Beispiel
clickElement('accessibilityId', 'search_field', 5);
client.sendKeys('hello');Siehe auch client.hideKeyboard、client.setClipboard
client.lock#
Lock the screen; client.unlock() unlocks it and client.locked() tells whether it is locked.
client.lock(): object;
client.unlock(): object;
client.locked(): boolean;Rückgabewert
| Typ | Beschreibung |
|---|---|
object | boolean | lock / unlock return the raw WDA response; locked returns true while the screen is locked. |
Hinweise
- Unlocking only works on devices without a passcode.
Beispiel
if (client.locked()) {
client.unlock();
}