TestProject Forum

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.