Alternative of exists() in UIObject2

Viewed 902

With UIObject we have a method : exists() to check if view exists
I am looking for same alternative with UIObject2.

2 Answers

You can do it this way:

import android.support.test.uiautomator.UiDevice; 
import android.support.test.uiautomator.UiObject2;
import android.support.test.InstrumentationRegistry; 


private UiDevice device = UiDevice.getInstance(
    InstrumentationRegistry.getInstrumentation()
);
List<UiObject2> objs = device.findObjects(...)
// Now you can check if objs.size() > 0

Yes! hasObject() function

Like this:

 if (!item.hasObject(By.res("com.mkurbanov.degishmeler:id/item_dugs_date")))
                    break;
 if (!item.hasObject(By.res("com.mkurbanov.degishmeler:id/text_like")))
                    break;
Related