2012-10-17 110 views
0

我想輸入一些文本到我的android應用程序中的文本字段。我安裝了應用程序,並在第二頁我想搜索一些地方。爲此我需要輸入一些文字。如何使用monkeyrunner在文本字段中輸入文本

I tried `device.press('KEYCODE_BUTTON_SELECT',MonkeyDevice.DOWN_AND_UP) 
device.press('KEYCODE_i','DOWN_AND_UP') 
device.press('KEYCODE_n','DOWN_AND_UP') 
device.press('KEYCODE_d','DOWN_AND_UP') 
device.press('KEYCODE_i','DOWN_AND_UP') 
device.press('KEYCODE_a','DOWN_AND_UP') 

或 Device.type(印度)`

但這些命令不工作的我的應用程序,它不進入字符串「印度」我的應用程序文本filed.But這正與手機本機搜索文本提交。

我安裝的Android View Client並導入下面的事情

import from com.dtmilano.android.view client import View Client 
from com.android.monkey runner import Monkey Runner, Monkey Device 

然後我寫了這樣的代碼

vc = ViewClient(device) 
vc.dump() 
address= vc.findViewById('search') 
address.type('india') 

但它顯示錯誤:「無類型」對象有沒有屬性'類型'。

你能幫我做這件事嗎?

回答

0

您可能需要使用:

address = vc.findViewByIdOrRaise('search') 

,以避免以檢查未發現address場。 另外,我猜這個ID是'id/search'

最後一個上提醒一句:

address.type('india') 

這是EditText.type(),所以你必須確保addressEditText

print address.getClass() 

否則,你可以使用

address.touch() # to focus it 
device.type('india') 

或(因爲有時鍵入()扼流圈)

address.touch() # to focus it 
for c in 'india': 
    device.type(c) 
+0

您好我嘗試以下code..It不鍵入字「印」和表示一個用戶警告「不支持的Android版10」 地址= vc.findViewByIdOrRaise(「ID /搜索」) 地址。 touch() device.type('india') – user1722227

+0

address = vc.findViewByIdOrRaise('search')address.type('india')..屬性錯誤顯示。屬性錯誤類型 – user1722227

+0

我告訴你驗證'地址「實際上是一個EditText或採取device.type()方法 –

相關問題