Mobile Androidviewclient未显示唯一ID';Android4.4.2操作系统上的s

Mobile Androidviewclient未显示唯一ID';Android4.4.2操作系统上的s,mobile,automation,android-4.2-jelly-bean,android-4.4-kitkat,androidviewclient,Mobile,Automation,Android 4.2 Jelly Bean,Android 4.4 Kitkat,Androidviewclient,当使用Android 4.4.2 Kitkat OS设备时,不会显示唯一ID。下面是我在示例中使用的代码 import sys import os # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.

当使用Android 4.4.2 Kitkat OS设备时,不会显示唯一ID。下面是我在示例中使用的代码

import sys
import os

# PyDev sets PYTHONPATH, use it
try:
for p in os.environ['PYTHONPATH'].split(':'):
if not p in sys.path:
sys.path.append(p)
except:
pass

try:
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass

from com.dtmilano.android.viewclient import ViewClient
ViewClient(*ViewClient.connectToDeviceOrExit(verbose=True)).traverse(transform=ViewClient.TRAVERSE_CIT)
三星OS4.4.2-在使用OS 4.4.2的Nexus5上也观察到了相同的行为

android.widget.FrameLayout  
android.widget.LinearLayout  
android.widget.FrameLayout android:id/content 
android.widget.FrameLayout com.sec.android.app.launcher:id/animation_layer 
android.widget.FrameLayout com.sec.android.app.launcher:id/home_view 
android.widget.FrameLayout com.sec.android.app.launcher:id/home_container 
android.widget.FrameLayout  
android.view.View com.sec.android.app.launcher:id/workspace 
android.view.View  
android.view.View  
android.view.View  
android.appwidget.AppWidgetHostView  
android.widget.FrameLayout  
android.widget.LinearLayout com.google.android.googlequicksearchbox:id/search_plate 
android.widget.LinearLayout  
LG G2操作系统4.2

android.widget.FrameLayout id/no_id/1 
android.widget.LinearLayout id/no_id/2 
android.widget.FrameLayout id/no_id/3 
android.widget.FrameLayout id/no_id/4 
android.widget.FrameLayout id/no_id/5 
android.view.View id/no_id/6 
android.view.View id/no_id/7 
android.view.View id/no_id/8 
android.appwidget.AppWidgetHostView id/no_id/9 
android.widget.FrameLayout id/no_id/10 
android.widget.LinearLayout id/no_id/11 
android.widget.LinearLayout id/no_id/12 
android.widget.ImageButton id/no_id/13 
android.widget.LinearLayout id/no_id/14 
android.widget.ImageButton id/no_id/15 
android.widget.TextView id/no_id/16 Log Viewer
android.widget.TextView id/no_id/17 CatLog
另外,vc.findViewById('id/tv_search').type('Donald')不起作用。但是ID-'ID/no_ID/23'在所有设备上都可以正常工作


请帮助我解决此问题。

您将获得不同的结果,因为即使脚本相同,后端(
uiautomator
在本例中)也会为同一应用程序返回不同的数据。以前,
uiautomator
没有在任何版本上返回ID,但在KitKat中进行了改进。这个问题是为什么如果需要ID,就必须求助于其他后端替代方案(如ViewServer或LocalViewServer)的原因之一


AndroidViewClient尝试处理android版本和实现中的所有这些差异,并为您提供一个单一界面(分配唯一id的地方),允许您创建跨版本测试脚本。

在您的示例中,我看不到任何带有
id/tv\u search
的视图。修复这些findX()方法问题的一个良好起点是使用
culebra
生成模板脚本。如果某些设备上没有ID,AndroidViewClient只能提供
uiautomator dump
给出的ID,你可以信任按外观顺序分配的唯一ID,并且对于同一个应用程序应该是相同的。我的问题是,为什么我使用相同的脚本获得两种不同类型的ID。在kitkat设备上,我得到了开发者在开发应用程序时给出的ID。在4.2.2设备上,我获得了AVC默认ID。以上就是我提到的例子。i、 e id/tv_search是OS 4.4.2上某个元素的id,id/no_id/23是OS 4.2.2上同一元素的id。感谢米兰的快速回复。是否可以触摸设备id,即id/tv_搜索而不是AVC默认id。AVC无法识别除默认id以外的id。如果我错了,请纠正我。使用应用程序ID而不是唯一ID的原因是,我的应用程序有多个屏幕,并且在每个屏幕上都有相同的ID,例如:ID/no_ID/10。此外,我在我们的应用程序中有一个相对的布局,因此,基于背景屏幕,唯一的AVC ID正在改变。有时是id/no\u id/10,有时是id/no\u id/12等等,提前谢谢!!当然,如果可用,应用程序ID是首选的,你完全正确,但正如我提到的,这只发生在kitKat中。是的,一旦你有了对视图的引用,你可以触摸或其他任何东西。是的,但是Kitkat中发生的事情是,当我使用应用程序ID时,它不会识别和执行任何操作,但当我使用默认ID时,它会起作用。如何克服这个问题?应该认识到,你可能做错了什么。