當前位置: 首頁>>代碼示例>>Java>>正文


Java UiSelector.instance方法代碼示例

本文整理匯總了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;
}
 
開發者ID:appium,項目名稱:appium-uiautomator2-server,代碼行數:56,代碼來源:UiObjectElement.java


注:本文中的android.support.test.uiautomator.UiSelector.instance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。