Java Code Examples for androidx.test.uiautomator.UiObject#exists()
The following examples show how to use
androidx.test.uiautomator.UiObject#exists() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScrollToElement.java From appium-uiautomator2-server with Apache License 2.0 | 6 votes |
@Override public boolean scrollIntoView(UiObject obj) throws UiObjectNotFoundException { if (obj.exists()) { return true; } // we will need to reset the search from the beginning to start search flingToBeginning(getMaxSearchSwipes()); if (obj.exists()) { return true; } for (int x = 0; x < getMaxSearchSwipes(); x++) { if (!scrollForward()) { return false; } if (obj.exists()) { return true; } } return false; }
Example 2
Source File: BrowserSignInTest.java From samples-android with Apache License 2.0 | 5 votes |
private void acceptChromePrivacyOption() throws UiObjectNotFoundException { UiSelector selector = new UiSelector(); UiObject accept = mDevice.findObject(selector.resourceId(ID_ACCEPT)); accept.waitForExists(TRANSITION_TIMEOUT); if (accept.exists()) { accept.click(); } UiObject noThanks = mDevice.findObject(selector.resourceId(ID_NO_THANKS)); noThanks.waitForExists(TRANSITION_TIMEOUT); if (noThanks.exists()) { noThanks.click(); } }
Example 3
Source File: DeviceAutomator.java From device-automator with MIT License | 5 votes |
private void clickPermissionDialogButton(String permission, int buttonIndex) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(getTargetContext(), permission) != PackageManager.PERMISSION_GRANTED) { try { UiObject allowPermissions = mDevice.findObject(new UiSelector() .clickable(true) .checkable(false) .index(buttonIndex)); if (allowPermissions.exists()) { allowPermissions.click(); } } catch (UiObjectNotFoundException ignored) {} } }
Example 4
Source File: AndroidTestsUtility.java From line-sdk-android with Apache License 2.0 | 4 votes |
public static boolean checkTextExists(String text) { UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); UiObject result = uiDevice.findObject(new UiSelector().text(text)); return result.exists(); }
Example 5
Source File: UiObjectElement.java From appium-uiautomator2-server with Apache License 2.0 | 4 votes |
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<>(); // 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; }