需要确定的XPath使用appium Android的元素 [英] Need to identify xpath for android element using appium

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

问题描述

我测试我使用Appium架构的Andr​​oid应用程序。
我有没有IDS对自己的观点(我不希望添加...)的机器人的屏幕,所以我想使用XPath。

这是屏幕怎么看起来像的 UI Automator的浏览器的:

我要得到所有的相对布局(红色标记 - 十六项)

我试过如下:

 列表< 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]\");

但我没有得到任何物品。

我没有成功在网上搜索,发现在未来的XPath教程,尝试更多的选择,但一次。

http://www.zvon.org/comp/r/啧啧XPath_1.html#前奏

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

请问AP preciate任何帮助。


解决方案

现在有使用XPath Android上的一对夫妇讨厌的错误解释你所看到的行为。他们被安排固定在 1.3.1版本


  1. 您不能根节点搜索.. 链接

    • 不幸的是,这意味着一个详细的XPath是有可能的XPath的(双关语)成功


  2. 您有时会元素的240当你只有16 链接

在理想情况下,你可以看看所有16 RelativeLayout的 android.widget.LinearLayout 母公司的资源ID >和再这样做:

  // android.widget.LinearLayout [@资源ID =富] / android.widget.RelativeLayout


因为你给的布局之一的位置您详细的解决方案没有奏效[2]

这是固定:

<$p$p><$c$c>//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

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

我在找到使用 UiAutomator 定位策略的问题的解决方案,但没有解答(因为 .fromChild() .fromParent()似乎被打破)

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.

This is how the screen looks like in UI Automator Viewer:

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

I tried the following:

 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.

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/

Would appreciate any help.

解决方案

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. You can't search by root nodes.. link
    • Unfortunately, this means that a verbose xpath is likely the xpath(pun) to success
  2. You sometimes get 240 of an element when you only have 16 link

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


Your verbose solution did not work because you gave one of the layouts a position of [2].

Here it is, fixed:

//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.

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)

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

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