본문으로 건너뛰기
CloudClick iOS

Selectors

A selector only builds an element object and does not look anything up yet; the lookup happens when you call exists / click / getText / getRect. Compared with findElement it can pick the n-th match and include hidden elements, but it does not wait.

기능 개요

  • ·Selector names match the values of findElement's first argument one to one
  • ·accessibilityId is the most stable: it does not change with the UI language or copy edits
  • ·xpath is flexible but slow — prefer classChain / predicate when they can express the same thing

client.label#

Match elements whose text is exactly the value.

typescript
client.label(value: string, visibleOnly?: boolean, index?: number): Element;

매개변수

이름타입필수기본값설명
valuestring예—The element's text; must match exactly.
visibleOnlyboolean아니오trueOnly match visible elements. Pass false to include hidden ones (covered, or scrolled off screen).
indexnumber아니오0Which match to take when there are several, counting from 0.

반환값

타입설명
ElementAn element object. Nothing is looked up yet — the lookup happens when you call exists / click / getText / getRect.

예제

javascript
var ok = client.label('OK');
if (ok.exists()) {
  ok.click();
}
var second = client.label('Follow', true, 1);   // the second "Follow"

관련 항목 client.labelContains、findElement

client.labelContains#

Match elements whose text contains the value.

typescript
client.labelContains(value: string, visibleOnly?: boolean, index?: number): Element;

매개변수

이름타입필수기본값설명
valuestring예—The text to look for inside the element's text.
visibleOnlyboolean아니오trueOnly match visible elements. Pass false to include hidden ones (covered, or scrolled off screen).
indexnumber아니오0Which match to take when there are several, counting from 0.

반환값

타입설명
ElementAn element object. Nothing is looked up yet — the lookup happens when you call exists / click / getText / getRect.

예제

javascript
var follow = client.labelContains('Follow');
if (follow.exists()) {
  follow.click();
}

관련 항목 client.label

client.accessibilityId#

Match by the element's name (its accessibilityIdentifier, set by the app's developer). The most stable way to locate an element: it does not change with the UI language or copy edits.

typescript
client.accessibilityId(value: string, visibleOnly?: boolean, index?: number): Element;

매개변수

이름타입필수기본값설명
valuestring예—The element's name. Click the element in the console's inspector to see it.
visibleOnlyboolean아니오trueOnly match visible elements. Pass false to include hidden ones (covered, or scrolled off screen).
indexnumber아니오0Which match to take when there are several, counting from 0.

반환값

타입설명
ElementAn element object. Nothing is looked up yet — the lookup happens when you call exists / click / getText / getRect.

예제

javascript
var submit = client.accessibilityId('submit_button');
if (submit.exists()) {
  submit.click();
}

관련 항목 findElement

client.xpath#

Match by XPath. Flexible but slow: the whole element tree is serialised before the query runs, which can take seconds on busy screens.

typescript
client.xpath(value: string): Element;

매개변수

이름타입필수기본값설명
valuestring예—The XPath expression. The first match is used; write (//expression)[n] for the n-th.

반환값

타입설명
ElementAn element object. Nothing is looked up yet — the lookup happens when you call exists / click / getText / getRect.

주의사항

  • If classChain or predicate can express it, do not use XPath.

예제

javascript
var btn = client.xpath('//XCUIElementTypeButton[@name="OK"]');
if (btn.exists()) {
  btn.click();
}

관련 항목 client.classChain、client.predicate

client.classChain#

Match by an iOS class chain — much faster than XPath.

typescript
client.classChain(value: string, index?: number): Element;

매개변수

이름타입필수기본값설명
valuestring예—The class chain, for example **/XCUIElementTypeCell[`label CONTAINS "General"`].
indexnumber아니오0Which match to take when there are several, counting from 0.

반환값

타입설명
ElementAn element object. Nothing is looked up yet — the lookup happens when you call exists / click / getText / getRect.

예제

javascript
var cell = client.classChain('**/XCUIElementTypeButton[`label == "OK"`]');
if (cell.exists()) {
  cell.click();
}

관련 항목 client.predicate、client.xpath

client.predicate#

Match with an NSPredicate expression.

typescript
client.predicate(value: string, index?: number): Element;

매개변수

이름타입필수기본값설명
valuestring예—The predicate, for example label BEGINSWITH 'Con' or type == 'XCUIElementTypeButton' AND visible == true.
indexnumber아니오0Which match to take when there are several, counting from 0.

반환값

타입설명
ElementAn element object. Nothing is looked up yet — the lookup happens when you call exists / click / getText / getRect.

예제

javascript
var btn = client.predicate('type == "XCUIElementTypeButton" AND label CONTAINS "Follow"');
if (btn.exists()) {
  btn.click();
}

관련 항목 client.classChain

client.className#

Match by element type, for example XCUIElementTypeCell or XCUIElementTypeSwitch.

typescript
client.className(value: string, index?: number): Element;

매개변수

이름타입필수기본값설명
valuestring예—The element type name.
indexnumber아니오0Which match to take when there are several, counting from 0.

반환값

타입설명
ElementAn element object. Nothing is looked up yet — the lookup happens when you call exists / click / getText / getRect.

예제

javascript
var firstCell = client.className('XCUIElementTypeCell', 0);
if (firstCell.exists()) {
  firstCell.click();
}

관련 항목 client.predicate