问题
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