React Native Android testing with AccessibilityID

My ReactNative App contain button that when recorded gives me multiple locators:

ID: icon_icon_user
XPATH: //android.widget.TextView[@text = '']
XPATH: //android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.widget.TextView
XPATH: //android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.widget.TextView[1]

When I record it on android, it results with element:

Sadly when I remove xPath locators and stay with ID or ACCESSIBILITYID, TestProject is unable to find element and click it.
Finding same element by ACCESIBILITYID on iOS devices works properly.

Is there any option to locate elements by “resource-id” available in the element as it appears on screen on android devices?:

I’m worried that if I modify UI of screen slightly, I’ll have to update locators to mirror UI change and view hierarchy. That’s why I want to use IDs that I’ve defined already in code.

Hi @SCTester
Yes you can find and element using its attributes in your situation resource-id.

Here is an example Click on save element

Add to the xpath created resource-id
for example
//android.widget.TextView[@resource-id= ‘android:id/input’]

Please let me know if you managed.

@Tal.Efraim thank you for answer. Sadly it doesn’t work for me.
Element defined like below:
TYPE = android.view.ViewGroup
XPATH = //android.view.ViewGroup[@resource-id= ‘android:id/button_forgot_credentials’]

results with:

where nodes defined in view look like below:

...
<node index="6" text="" resource-id="button_forgot_credentials" class="android.view.ViewGroup" package="com.schange.client.vanilla.android.mobile" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[79,1531][1001,1661]">
  <node index="0" text="FORGOT PASSWORD?" resource-id="" class="android.widget.TextView" package="com.schange.client.vanilla.android.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[302,1570][778,1623]" />
</node>
...

Could you please guide me, where I’m making mistake?

Additionally, when looking for element with ‘locator’ feature, it is unable to find element with given resource-id, despite the fact that resource-id is visible by TestProject:

Test fails with given TESTID as a locator:

However Locator finder is able to find element with given id:

My apologies for spam in comments, I can add only one image per comment.

This topic was automatically closed after 180 days. New replies are no longer allowed.