2

我是 Appium 移动应用程序测试的新手。该应用程序是用 react-native 编写的。

我在移动屏幕上定位元素时遇到问题。使用 uiAutomatorViewer 查看元素详情时,没有为每个元素显示类名,因此无法定位元素。似乎只显示元素的索引。

这是开发人员的错误,还是有办法找到我需要知道的元素?

在此处输入图像描述

这是页面的xml。你可以粗略地看一下,你可以知道没有额外的信息:

<?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>
4

1 回答 1

1

从您的屏幕截图中我可以看到,您可以使用一个index 属性来识别您的元素,因此您可以尝试以下XPath 选择器

//*[@index='1']

但是很难说它是否会是一个独特的匹配,继续考虑执行Source命令并粘贴 UI 层次结构而不是屏幕的照片。

查看应用程序 DOM 结构的另一种方法是:

于 2019-08-24T09:44:24.810 回答