需要确定的XPath使用appium Android的元素 [英] Need to identify xpath for android element using appium
问题描述
我测试我使用Appium架构的Android应用程序。
我有没有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#前奏
请问AP preciate任何帮助。
现在有使用XPath Android上的一对夫妇讨厌的错误解释你所看到的行为。他们被安排固定在 1.3.1版本
在理想情况下,你可以看看所有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
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
- You can't search by root nodes.. link
- Unfortunately, this means that a verbose xpath is likely the xpath(pun) to success
- 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 RelativeLayout
s 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屋!