Android XPath索引问题

huangapple go评论95阅读模式
英文:

Android XPath index issue

问题

非常新手对于Android测试。我遇到了这个Xpath

xpath:(//android.widget.ImageView [1])[3]

我知道在ImageView 1中,“1”是元素的索引。这里的[3]是什么?

更新:

我正在运行一个测试(移动应用)。上面的XPath是为了点击铃铛图标。它确实成功地点击了铃铛图标。但是今天当我运行我的测试时,它没有点击铃铛图标,而是点击了用户头像。

[![在此输入图片说明] 1] 1

使用appium,我找到了铃铛图标的xpath如下:

xpath:/ hierarchy / android.widget.FrameLayout / android.widget.LinearLayout / android.widget.FrameLayout / android.widget.LinearLayout / android.widget.FrameLayout / android.widget.FrameLayout / android.view.ViewGroup / android.view.ViewGroup / android.view.ViewGroup [1] / android.view.ViewGroup / android.view.ViewGroup / android.view.ViewGroup / android.view.ViewGroup / android.view.ViewGroup [2] / android.view.ViewGroup [1] / android.view.ViewGroup [2] / android.view.ViewGroup / android.widget.ImageView

现在当我使用这个新的xpath时,铃铛图标被点击了。

这两个Xpath是相同的吗?为什么这个新的xpath如此之长?有没有缩短它的方法?任何形式的帮助都非常感谢!

英文:

Very new to Android Testing.<br/>
I came across this Xpath

xpath: (//android.widget.ImageView[1])[3]

I know that in ImageView1 "1" is the index of the element.<br/>
What is [3] here???

Update:<br/>

I am running a test (mobile App). The above XPath is to tap on the Bell icon.<br/>
It did tap on the bell icon perfectly.<br/>
But today when I run my test it doesn't tap on the Bell icon instead it taps on the user Profile Picture.

Android XPath索引问题

Using appium I found the xpath of the Bell icon as below:

xpath: /hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup/android.widget.ImageView

Now when I use this new xpath the Bell icon is clicked.

Are both the Xpaths same?? <br/>
Why is this new xpath so long? is there a way to shorten this??<br/>
Any kind of help is really Appreciated!!!

答案1

得分: 1

表达式 //android.widget.ImageView[1] 选择了每个作为其父级的第一个子项的 android.widget.ImageView。这通常会选择一组节点。[3] 选择了此集合中的第三个节点。

英文:

The expression //android.widget.ImageView[1] selects every android.widget.ImageView that is the first child of its parent. This will in general select a set of nodes. The [3] selects the third node in this set.

答案2

得分: 0

尝试使用类名访问铃铛按钮。

(//*[@class="类名"])[2]

(//*[@class="android.widget.ImageView"])[2]

英文:

Try to access bell button using class name.

(//*[@class="Class name"])[2]

  (//*[@class=&quot;android.widget.ImageView&quot;])[2]

答案3

得分: 0

你正在使用之前提到的Appium来获取绝对XPath,而你正在使用的类似于 //android.widget.ImageView1)[3] 是该图标的相对XPath。

绝对XPath:它是从根元素到特定元素的路径。
相对XPath:它是元素的引用路径或特定路径到元素。

英文:

You are getting the absolute xpath using the appium(which you have stated above) and the one you are using like //android.widget.ImageView1)[3] is the relative xpath of the icon.

Absolute xpath : It is the path from the root element to the particular element.
Relative xpath : It is the reference path of the element or particular path to the element.

huangapple
  • 本文由 发表于 2020年8月20日 15:18:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63500091.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定