'Locating elements with no class name in Appium
Using Appium testing for mobile applications. The app is written in react-native.
I'm having trouble locating elements on the mobile screen. When using uiAutomatorViewer to view the element details, no class name are displayed for every element, so there is no way of locating the elements. It seems like only the index of the elements are being displayed.
Is that the developer's mistake, or is there a way of locating the elements that I need to know?
This is the xml of the page. You can roughly look through it and you can tell there's no additional information:
<?xml version="1.0" encoding="UTF-8"?>
<hierarchy rotation="0">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2792]">
<node index="0" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2792]">
<node index="0" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2792]">
<node index="0" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,168][231,256]">
<node index="0" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,168][231,256]" />
</node>
<node index="1" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[1209,168][1440,256]">
<node index="0" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[1209,168][1440,256]" />
</node>
<node index="2" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[56,326][119,391]" />
<node index="3" text="Find someone passionate about ..." resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[154,288][1332,428]" />
<node index="4" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="true" long-clickable="false" password="false" selected="false" bounds="[0,574][1440,1104]">
<node index="3" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,617][347,1019]">
<node index="0" text="Leon" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,642][171,759]" />
<node index="1" text="So" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[8,759][110,863]" />
<node index="2" text="READING" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,895][248,993]" />
</node>
<node index="4" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[400,592][1041,1039]">
<node index="0" text="Tim" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[629,620][813,750]" />
<node index="1" text="Choy" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[604,750][837,866]" />
<node index="2" text="POTATOES" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[485,901][956,1010]" />
</node>
<node index="5" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[1094,617][1440,1019]">
<node index="0" text="Kevin" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[1252,642][1440,759]" />
<node index="1" text="Feng" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[1280,759][1440,863]" />
<node index="2" text="DOGS" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[1263,895][1440,993]" />
</node>
</node>
<node index="5" text="New Matches" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[35,484][1440,575]" />
<node index="6" text="Daily Feed" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[35,1104][1440,1194]" />
<node index="7" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="true" long-clickable="false" password="false" selected="false" bounds="[0,1195][1440,2792]">
<node index="0" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[258,1465][1185,2451]">
<node index="0" text="Paul" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[565,1672][878,1861]" />
<node index="1" text="Deng" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[557,1861][886,2029]" />
<node index="2" text="SOCCER" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[440,2061][1003,2228]" />
</node>
<node index="1" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[235,1373][1202,2402]">
<node index="0" text="Joy" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[582,1589][855,1787]" />
<node index="1" text="Xiao" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[575,1787][864,1961]" />
<node index="2" text="BUNNIES" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[391,1995][1047,2170]" />
</node>
<node index="2" text="" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[216,1279][1224,2351]">
<node index="0" text="Henry" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[476,1504][965,1710]" />
<node index="1" text="Last" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[583,1710][857,1892]" />
<node index="2" text="FRISBEE" resource-id="" class="" package="me.passionfruit.app.android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[416,1927][1024,2109]" />
</node>
</node>
</node>
</node>
</node>
</hierarchy>
Solution 1:[1]
From what I can see from your screenshot there is index
attribute which you can use for identifying your element so you could try the following XPath selector
//*[@index='1']
however it's hard to say whether it will be a unique match or not, going forward consider executing Source command and pasting the UI hierarchy instead of photo of your screen.
Another approaches to view application DOM structure are:
- Appium Desktop
- Android Device Monitor
- Android Studio Layout Inspector
- Appium Studio - this one provides
Copy Unique XPath
feature
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dmitri T |