需要使用appium识别android元素的xpath [英] Need to identify xpath for android element using appium

查看:61
本文介绍了需要使用appium识别android元素的xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Appium 框架测试我的 Android 应用程序.我有一个没有视图 id 的 android 屏幕(我不想添加...),所以我想使用 Xpath.

I am testing my Android application using Appium framework. I have an android screen that doesn't have ids for its views (and I don't want to add...), so I thought using Xpath.

UI Automator Viewer 中的屏幕如下所示:

我想获取所有相关的布局(用红色标记 - 16 项)

I want to get all the relative layouts (marked in red - sixteen items)

我尝试了以下方法:

 List<WebElement> webElementslist =
 mAppDriver.findElementsByXPath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ViewAnimator[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]");

但我没有收到任何物品.

But I didn't get any items.

我在网上搜索并找到了下一个 xpath 教程,尝试了更多选项,但还是没有成功.

I searched the web and found the next xpath tutorials, tried more options, but again with no success.

http://www.zvon.org/comp/r/tut-XPath_1.html#intro

http://www.w3.org/TR/xpath/

非常感谢您的帮助.

推荐答案

现在,Android 上的 XPath 存在一些令人讨厌的错误,这些错误解释了您所看到的行为.它们计划在 1.3.1 版本

Right now there's a couple nasty bugs with XPath on android that explain the behaviors you're seeing. They are scheduled to be fixed in the 1.3.1 release

  1. 您无法按根节点搜索.. 链接
    • 不幸的是,这意味着冗长的 xpath 很可能是成功的 xpath(pun)

理想情况下,您可以查找所有 16 个 RelativeLayoutandroid.widget.LinearLayout 父项的资源 ID,然后执行以下操作:

Ideally, you could look for the resource-id of the android.widget.LinearLayout parent of all 16 RelativeLayouts and then do something like:

//android.widget.LinearLayout[@resource-id="foo"]/android.widget.RelativeLayout

<小时>

您的详细解决方案不起作用,因为您为其中一个布局指定了 [2] 的位置.

这是固定的:

//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ViewAnimator[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.RelativeLayout

.... 请使用第一个解决方案.

.... please, please use the first solution.

我正在研究使用 UiAutomator 定位器策略解决您的问题,但还没有答案(因为 .fromChild().fromParent() 好像坏了)

I'm looking into a solution for your problem using UiAutomator locator strategy, but no answers yet (because .fromChild() and .fromParent() seem to be broken)

这篇关于需要使用appium识别android元素的xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆