Appium 取不到页面的所有元素的 xpath

55hhy · 2015年07月08日 · 最后由 55hhy 回复于 2015年07月09日 · 1602 次阅读

appium + cucumber,语言 ruby

我用 uiautomatorviewer 检查会看到

然后用脚本只到了 uiautomatorviewer 看到的 imageview 那里,下面的元素就没有。

  current_activity
#.LoginActivity
  get_source
#<?xml version="1.0" encoding="UTF-8"?>

<hierarchy rotation="0">

<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="Package_name" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="" instance="0">

<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="Package_name" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="" instance="0">

<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="Package_name" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="" instance="1">

<android.view.View index="0" text="" class="android.view.View" package="Package_name" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="Package_name:id/decor_content_parent" instance="0">

<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="Package_name" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="android:id/content" instance="2">

<android.widget.RelativeLayout index="0" text="" class="android.widget.RelativeLayout" package="Package_name" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="" instance="0">

<android.view.View index="0" text="" class="android.view.View" package="Package_name" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="Package_name:id/sliding_layout" instance="1">

<android.widget.RelativeLayout NAF="true" index="0" text="" class="android.widget.RelativeLayout" package="Package_name" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="Package_name:id/modules_page" instance="1">

<android.widget.ImageView index="0" text="" class="android.widget.ImageView" package="Package_name" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[240,846][839,929]" resource-id="Package_name:id/ef_logo" instance="0"/>

</android.widget.RelativeLayout>

</android.view.View>

</android.widget.RelativeLayout>

</android.widget.FrameLayout>

</android.view.View>

</android.widget.FrameLayout>

</android.widget.LinearLayout>

<android.view.View index="1" text="" class="android.view.View" package="Package_name" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,1776][1080,1920]" resource-id="android:id/navigationBarBackground" instance="2"/>

</android.widget.FrameLayout>

</hierarchy>

最后说一下,我们的业务需求是打开 app 之后先是一张图片,然后等 3 秒出来 username 和 password 的输入框,我看开发是将所在的 relativelayout 放在了 里面,是不是因为这个原因?如果是的话,有解吗?

共收到 3 条回复 时间 点赞

我的粗暴的解决方法:找到 Package_name:id/ef_logo 然后 click 一下,然后就找到了。

你是等到出来了 username 和 password 输入框才 get source 的吗?

#2 楼 @chenhengjie123 是的 页面上看到是有的 但是实际还是要 click 一下才拿到 username 和 password。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册