Reputation: 103
I trying to click on a button with UiAutomator, but receive error "androidx.test.uiautomator.UiObjectNotFoundException"
I tried to locate object in two ways.
UiObject cartButton = uiDevice.findObject(new Selector().resourceId("R.id.group_cart_add_button"));
UiObject2 cartButton = uiDevice.findObject(By.res(InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName(), "R.id.group_cart_add_button"));
Then I use cartButton.click()
but both times I receive an error.
In hierarchy this object is exist
And when I try to find it in Evaluate tool, I can do it:
But if I try to click, I receive an error:
Why?
Upvotes: 1
Views: 3369
Reputation: 6160
You can do the following:
String packageName = "your-app-package-name"
String fullCartButtonResourceId = packageName + ":id/group_cart_add_button";
UiObject2 cartButton = mDevice.findObject(By.res(uk));
or
UiObject cartButton = findObject(new UiObject(new UiSelector().resourceId(fullCartButtonResourceId));
Upvotes: 2