0

使用Android 4.4.2 Kitkat OS設備的設備沒有顯示唯一標識。下面是我從示例中使用的代碼。Androidviewclient在Android4.4.2上未顯示唯一標識號OS

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 - 上Nexus5開始觀察到操作系統相同的行爲4.4.2

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 OS 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('身份證/ tv_search')。type('Donald')不起作用。但ID-'id/no_id/23'在所有設備上工作正常。

請幫我解決這個問題。

+0

我在你的示例中看不到任何帶'id/tv_search'的視圖。解決這些findX()方法問題的一個好的起點是使用'culebra'來生成一個模板腳本。 –

+0

** AndroidViewClient **只能提供'uiautomator dump'給出的id,如果id在某些設備上不存在,那麼您可以信任按照外觀順序分配的**唯一id,並且應該相同同一個應用程序。 –

+0

我的問題是爲什麼我使用相同的腳本獲得兩種不同類型的ID。在kitkat設備上,我獲得了由開發人員在開發應用程序時提供的ID。在4.2.2設備上,我獲取AVC默認ID。 以上是我提到的例子。即id/tv_search是OS 4.4.2上元素的id,id/no_id/23是OS 4.2.2上相同元素的id。 – ASP

回答

0

您會得到不同的結果,因爲即使腳本相同,後端(本例中爲uiautomator)也會爲同一應用程序返回不同的數據。以前,uiautomator沒有在任何版本上返回id,但它在KitKat中得到了改進。這個問題是爲什麼如果你需要id的原因之一,你必須訴諸其他後端替代品,如ViewServer或LocalViewServer。

AndroidViewClient試圖處理Android版本和實現中的所有這些差異,爲您提供單個接口(這是分配唯一ID的地方),允許您創建跨版本測試腳本。

+0

感謝米蘭的快速回復。是否可以觸摸設備ID,即id/tv_search而不是AVC默認ID。 AVC無法識別該ID的默認ID以外的其他ID。如果我錯了,請糾正我。 – ASP

+0

使用App ID而不是唯一ID的原因是,我的應用程序有多個屏幕,並且在每個屏幕中它具有相同的ID,例如:id/no_id/10。另外,我在我們的應用程序中有一個相對佈局,由於這個原因,基於背景屏幕,唯一的AVC ID正在改變。有時,它是id/no_id/10,有時候,它是id/no_id/12等, 在此先感謝! – ASP

+0

當然,APP ID是首選,如果可用,你是完全正確的,但是這隻發生在kitKat中,正如我所提到的。是的,你可以觸摸或任何一個你有一個參考視圖。 –