본문으로 건너뛰기
CloudClick iOS

Screen & system

Read the current screen's element tree, size and screenshot, open links, write the clipboard, and handle system alerts.

client.source#

The current screen's element tree. Useful when working out a locator, but slow — keep it out of tight loops.

typescript
client.source(format?: "xml" | "json", accessible?: boolean): string;

매개변수

이름타입필수기본값설명
format"xml" | "json"아니오"xml"The output format.
accessibleboolean아니오falsePass true to keep only the accessibility-visible nodes, which makes the tree much smaller.

반환값

타입설명
stringThe element tree as text.

예제

javascript
var xml = client.source();
logd(xml.substring(0, 500));

관련 항목 setSnapshotMaxDepth

setSnapshotMaxDepth#

Set how deep the element tree is read (default 50). Deeper finds more deeply nested elements but is slower. Returns the previous depth so you can raise it temporarily and restore it afterwards.

typescript
setSnapshotMaxDepth(depth?: number): number | null;

매개변수

이름타입필수기본값설명
depthnumber아니오50The maximum depth.

반환값

타입설명
number | nullThe previous depth, or null when it could not be read.

주의사항

  • A depth of 0 means “root node only” in WDA, not “unlimited”. When restoring, skip values below 1.

예제

javascript
var prev = setSnapshotMaxDepth(80);
var found = findElement('accessibilityId', 'deep_button');
if (prev >= 1) {
  setSnapshotMaxDepth(prev);
}

관련 항목 client.source

client.windowSize#

The screen size in points. The result is cached.

typescript
client.windowSize(): { width: number; height: number };

반환값

타입설명
{ width, height }The screen width and height in points.

예제

javascript
var size = client.windowSize();
client.click(size.width / 2, size.height - 80);

client.screenshot#

Take a screenshot and get the image data. Colour, image and text lookups do not need this — call findColor / findImage / ocr directly.

typescript
client.screenshot(format?: "base64" | "bytes"): string | number[];

매개변수

이름타입필수기본값설명
format"base64" | "bytes"아니오"base64"base64 returns the PNG as a base64 string; bytes returns a byte array.

반환값

타입설명
string | number[]The PNG image data.

예외

예외발생 조건
WDAErrorformat is neither base64 nor bytes.

예제

javascript
var png = client.screenshot();
savePicVideo(png, 'screen.png');

관련 항목 keepScreen、savePicVideo

client.openUrl#

Have the system open a URL or a custom scheme (such as an app deep link).

typescript
client.openUrl(targetUrl: string): object;

매개변수

이름타입필수기본값설명
targetUrlstring예—The address to open.

반환값

타입설명
objectThe raw WDA response; rarely needed.

예제

javascript
client.openUrl('https://example.com');

client.setClipboard#

Write to the device clipboard; non-ASCII text is supported. Read it back with client.getClipboard().

typescript
client.setClipboard(content: string, contentType?: string): object;
client.getClipboard(): string;

매개변수

이름타입필수기본값설명
contentstring예—The text to write.
contentTypestring아니오"plaintext"The content type.

반환값

타입설명
object | stringsetClipboard returns the raw WDA response; getClipboard returns the clipboard text.

예외

예외발생 조건
WDAErrorcontent is not a string.

주의사항

  • iOS lets only the foreground app read the clipboard, so getClipboard brings WDA to the front through Siri, reads, and switches back — about 3 seconds in total.

예제

javascript
client.setClipboard('要粘贴的文字 / text to paste');
var text = client.getClipboard();

관련 항목 client.sendKeys

client.alert#

Handle system alerts (permission prompts, confirmations): check for one, accept, dismiss, or list the buttons.

typescript
client.alert.exists(): boolean;
client.alert.accept(): object;
client.alert.dismiss(): object;
client.alert.buttons(): string[];

반환값

타입설명
boolean | object | string[]exists is true when an alert is up; accept taps the last button (usually Allow or OK) and dismiss the first (usually Cancel or Don't Allow); buttons lists the button titles in order.

주의사항

  • To tap a specific button use client.alert.click('Button title'); client.alert.wait(seconds) waits for an alert to appear.

예제

javascript
if (client.alert.exists()) {
  client.alert.accept();
}