且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法在Appium中使用xpath定位元素

更新时间:2021-11-16 23:43:42

要递归搜索每个<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.

此外,请阅读xpath文档以获取更多信息

Also, read the xpath documentation for more information