本文整理匯總了Java中android.support.test.uiautomator.UiSelector.instance方法的典型用法代碼示例。如果您正苦於以下問題:Java UiSelector.instance方法的具體用法?Java UiSelector.instance怎麽用?Java UiSelector.instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.test.uiautomator.UiSelector
的用法示例。
在下文中一共展示了UiSelector.instance方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getChildElements
import android.support.test.uiautomator.UiSelector; //導入方法依賴的package包/類
public ArrayList<UiObject> getChildElements(final UiSelector sel) throws UiObjectNotFoundException {
boolean keepSearching = true;
final String selectorString = sel.toString();
final boolean useIndex = selectorString.contains("CLASS_REGEX=");
final boolean endsWithInstance = endsWithInstancePattern.matcher(selectorString).matches();
Logger.debug("getElements selector:" + selectorString);
final ArrayList<UiObject> elements = new ArrayList<UiObject>();
// If sel is UiSelector[CLASS=android.widget.Button, INSTANCE=0]
// then invoking instance with a non-0 argument will corrupt the selector.
//
// sel.instance(1) will transform the selector into:
// UiSelector[CLASS=android.widget.Button, INSTANCE=1]
//
// The selector now points to an entirely different element.
if (endsWithInstance) {
Logger.debug("Selector ends with instance.");
// There's exactly one element when using instance.
UiObject instanceObj = Device.getUiDevice().findObject(sel);
if (instanceObj != null && instanceObj.exists()) {
elements.add(instanceObj);
}
return elements;
}
UiObject lastFoundObj;
UiSelector tmp;
int counter = 0;
while (keepSearching) {
if (element == null) {
Logger.debug("Element] is null: (" + counter + ")");
if (useIndex) {
Logger.debug(" using index...");
tmp = sel.index(counter);
} else {
tmp = sel.instance(counter);
}
Logger.debug("getElements tmp selector:" + tmp.toString());
lastFoundObj = Device.getUiDevice().findObject(tmp);
} else {
Logger.debug("Element is " + getId() + ", counter: " + counter);
lastFoundObj = element.getChild(sel.instance(counter));
}
counter++;
if (lastFoundObj != null && lastFoundObj.exists()) {
elements.add(lastFoundObj);
} else {
keepSearching = false;
}
}
return elements;
}