How to enter text in text field using monkeyrunner

不羁岁月 提交于 2019-12-13 04:07:24

问题


i wanted to enter some text to a text field in my android application.I installed the app and in the second page i wanted to search for some places.For that i need to enter some text.

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')

or Device.type(India)`

But these commands are not working for my application.,It is not entering string "India" to my application text filed.But this is working with phone native search text filed.

I installed Android View Client and import the following things

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

Then i wrote the code like this

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

But it is showing error: 'None Type' object has no attribute 'type'.

Can u pls help me in doing this.


回答1:


You may want to use:

address = vc.findViewByIdOrRaise('search')

to avoid having to check for a not found address field. Also, I guess the id is 'id/search'.

And finally a word of warning on:

address.type('india')

This is EditText.type() so you have to be sure that address is an EditText

print address.getClass()

otherwise you can use

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

or (because sometimes type() chokes)

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


来源:https://stackoverflow.com/questions/12931728/how-to-enter-text-in-text-field-using-monkeyrunner

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!