testing-samples icon indicating copy to clipboard operation
testing-samples copied to clipboard

UiSelector.resourceId("myButtonId") not working

Open umarhussain15 opened this issue 7 years ago • 1 comments

I'm trying to get the facebook Login button in UIautomator but its failing to find the button given the id of the button

<com.facebook.login.widget.LoginButton
        android:id="@+id/login_button_facebook"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="0dp"
        android:layout_marginRight="0dp"
        android:layout_marginTop="0dp"/>

And here is the code how I'm accessing the button in my test case UiObject facebookButton = mDevice.findObject(new UiSelector().resourceId("login_button_facebook"));

Its failing to find the button saying :

android.support.test.uiautomator.UiObjectNotFoundException: UiSelector[RESOURCE_ID=login_button_facebook]
at android.support.test.uiautomator.UiObject.click(UiObject.java:416)

Please let me know if I'm doing it wrong. The documentation has not much detail about how to use it.

umarhussain15 avatar Oct 02 '17 06:10 umarhussain15

The id needs to include the package.

UiSelector().resourceId("com.example.something:id/login_button_facebook"));

This requirement is not well documented.

aroller avatar Nov 08 '19 21:11 aroller