AndroidViewClient,找不到视图
Posted
技术标签:
【中文标题】AndroidViewClient,找不到视图【英文标题】:AndroidViewClient, unable to find a view 【发布时间】:2016-10-24 22:36:42 【问题描述】:我正在使用 android 视图客户端来测试 UI。我的层次结构看起来像(从 android studio 的监控工具中看到):
我想要做的是抓住球的把手,并对其执行触摸动作。
但是,我无法得到它。 我用过:
from com.dtmilano.android.viewclient import ViewClient
print(ViewClient(*ViewClient.connectToDeviceOrExit()).findViewByTag("ImageView")
) as my python script.
输出显示无(但显然图片中可见图像视图)。
我在这里做错了什么?
编辑:
当我使用 culebra -G 并点击球时,我得到了这个:
no_id1 = vc.findViewByIdOrRaise("id/no_id/1") com_facebook_orca___id_back_button = vc.findViewByIdOrRaise("com.facebook.orca:id/back_button") no_id3 = vc.findViewByIdOrRaise("id/no_id/3") no_id3 = vc.findViewWithTextOrRaise(u'高分') com_facebook_orca___id_high_score_text = vc.findViewByIdOrRaise("com.facebook.orca:id/high_score_text") com_facebook_orca___id_high_score_text = vc.findViewWithTextOrRaise(u'29') no_id5 = vc.findViewByIdOrRaise("id/no_id/5") no_id5 = vc.findViewWithTextOrRaise(u'Current Best') com_facebook_orca___id_best_score_text = vc.findViewByIdOrRaise("com.facebook.orca:id/best_score_text") com_facebook_orca___id_best_score_text = vc.findViewWithTextOrRaise(u'1') 这里没有imageview。
另外,当我执行 ViewClient.findViewById("com.facebook.orca:id/ball") 时,我得到 None。
编辑 2
这是 dump -a 的输出
查看[class=android.widget.FrameLayout index=0 selected=false 检查=假可点击=假包=com.facebook.orca 文本= long-clickable=false enabled=true bounds=((0, 0), (1280, 672)) content-desc=focusable=false 聚焦=false uniqueId=id/no_id/1 checkable=false 资源 ID= 密码=false class=android.widget.FrameLayout 可滚动=false ] 父级=无 查看[ class=android.widget.ImageButton index=0 selected=false NAF=true clickable=true package=com.facebook.orca text=long-clickable=false enabled=true bounds=((0, 25), (64, 89)) content-desc=focusable=true 重点=假 uniqueId=id/no_id/2 可检查=假 resource-id=com.facebook.orca:id/back_button 密码=false class=android.widget.ImageButton 已检查=false 可滚动=false ] 父=android.widget.FrameLayout 视图[ class=android.widget.TextView 索引=1 选择=假检查=假 clickable=false package=com.facebook.orca text=高分 long-clickable=false enabled=true bounds=((1202, 35), (1270, 51)) content-desc=focusable=false 聚焦=false uniqueId=id/no_id/3 checkable=false 资源 ID= 密码=false class=android.widget.TextView 可滚动=false] 父=android.widget.FrameLayout 视图[ class=android.widget.TextView 索引=2 选中=假检查=假 clickable=false 包=com.facebook.orca text=29 长点击=false enabled=true bounds=((1226, 51), (1246, 76)) content-desc= focusable=falsefocused=false uniqueId=id/no_id/4 checkable=false resource-id=com.facebook.orca:id/high_score_text 密码=false class=android.widget.TextView 可滚动=false] 父=android.widget.FrameLayout 视图[ class=android.widget.TextView 索引=4 选择=假检查=假 clickable=false package=com.facebook.orca text=当前最佳 long-clickable=false enabled=true bounds=((591, 95), (689, 116)) content-desc=focusable=false focus=false uniqueId=id/no_id/5 checkable=false 资源 ID= 密码=false class=android.widget.TextView 可滚动=false] 父=android.widget.FrameLayout 视图[ class=android.widget.TextView 索引=5 选中=假检查=假 clickable=false 包=com.facebook.orca text=1 长点击=false enabled=true bounds=((612, 116), (667, 233)) content-desc= focusable=falsefocusable=false uniqueId=id/no_id/6 checkable=false resource-id=com.facebook.orca:id/best_score_text 密码=false class=android.widget.TextView 可滚动=false] parent=android.widget.FrameLayout
【问题讨论】:
该视图(球)不是可点击、可聚焦、可检查或长点击 (如您的转储所示)。这就是为什么culebra -G
不认为它是触摸的目标。当您在 android 应用上触摸它时会发生什么?您希望测试什么?
你能提供dump -a
的输出吗?
当我触到球的位置时,球会跳起来。这是 Facebook Messenger 应用程序,如果需要,您可以自己测试。我已经发布了转储-a
@harvey_slash 你赢了比赛吗? ;)
【参考方案1】:
我猜图片上的标签不是ImageView
的问题。
标签是在你的安卓应用上使用View.setTag() 设置的,但我认为你不需要它。
根据您的层次结构,您可以使用ViewClient.findViewById("com.facebook.orca:id/ball")
来获取对此类视图的引用。
我还建议您使用culebra -G
(请参阅Culebra GUI)然后触摸球图像,culebra 将生成正确的线以找到视图并触摸它。
【讨论】:
以上是关于AndroidViewClient,找不到视图的主要内容,如果未能解决你的问题,请参考以下文章
AndroidStudio 很多类红色高亮找不到,可以编译运行
Win7下在Visual Studio 2008里运行程序时出现找不到MFC90D.dll文件, Command Prompt找不指定路径