无法在Appium中使用xpath定位元素 [英] Unable to locate element using xpath in Appium
问题描述
我无法使用xpath识别元素.附上相同的屏幕截图.我想用<android.widget.ListView>
下的标签<android.widget.LinearLayout>
标识元素列表,并且使用了XPath表达式:
I am unable to identify an element using xpath. Attaching the screen shot of the same. I want to identify the list of elements with the tag <android.widget.LinearLayout>
under <android.widget.ListView>
and I have used the XPath expression:
//android.widget.ListView/android.widget.LinearLayout
这仅返回 1st 节点中的所有元素,而不返回<android.widget.LinearLayout>
下的元素.
This returns all the elements only from the 1st node and not the elements under <android.widget.LinearLayout>
.
有些身体可以帮助我吗?预先感谢.
Can some body help me out? Thanks in advance.
推荐答案
要递归搜索每个<android.widget.LinearLayout>
下的所有元素,请将其用作xpath:
To recursively search all elements under each of the <android.widget.LinearLayout>
you want this as your xpath:
xpath = '//android.widget.ListView/android.widget.LinearLayout/*'
但是要小心!这是非常繁重的操作.在屏幕快照中,看起来每个单元格每行至少有9-10个元素!向Appium索要所有这些元素会扼杀您的表现.
But be careful! This is a VERY heavy operation. In your screenshot, it looks that each one of your cells has atleast 9-10 elements per row! Asking Appium for all of those elements will kill your performance.
我建议您做以下事情:
xpath = '//android.widget.ListView/android.widget.LinearLayout//class_you_want'
尽管如此,我警告您不要使用第一种方法.您应该问自己是否只想要页面上的链接,文本等,然后使用第二种xpath查找方法.
Seriously though, I warn you against doing the first method. You should ask yourself if you only want the links on the page, or text, etc etc, and then use the second xpath finding method.
Also, read the xpath documentation for more information
这篇关于无法在Appium中使用xpath定位元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!