0

I am trying to enter some text to a text field in my android application using Monkeyrunner. I wrote the code like this:

device.press('KEYCODE_BUTTON_SELECT',MonkeyDevice.DOWN_AND_UP)

device.press('KEYCODE_U','DOWN_AND_UP')

device.press('KEYCODE_S','DOWN_AND_UP')

device.press('KEYCODE_E','DOWN_AND_UP')

device.press('KEYCODE_R','DOWN_AND_UP')

while running the first line,the text field is getting selected.But The string "user" is not typing there.But the same code i can run out of my application ,In the android native search field i can enter "user" string using this code. I tried the same with device.type('USER') command also.That is also not working

If i am using this code

device.press ('KEYCODE_DPAD_CENTER', MonkeyDevice.DOWN_AND_UP)

It is taping one center button. (In my application page one button is there in the middle of the page.)

akluth
  • 8,393
  • 5
  • 38
  • 42
user1722227
  • 21
  • 1
  • 7

3 Answers3

2

Try the following code. It's working in my case:

device.touch(x, y, MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(1)
device.type('USER')

In the command touch put the coordinates of your edittext instead of x and y

Yury
  • 20,618
  • 7
  • 58
  • 86
  • Hi Thanks for the reply but i am facing the same issue.The text box is getting selected through device.touch(x, y, MonkeyDevice.DOWN_AND_UP) code.But it is not taping there and not typing anything. – user1722227 Oct 08 '12 at 07:19
  • Device.touch is working with device related touch and clicks only.Its not going inside to the application. – user1722227 Oct 08 '12 at 07:33
  • Do you use EditText or TextView? If you use TextView you cannot type there. – Yury Oct 08 '12 at 08:09
  • EditText or TextView means what? While using the application in the android phone,i am able to write to the text field . – user1722227 Oct 08 '12 at 08:37
  • Then it's a very strange error. I think I cannot help in this case. Maybe something wrong with your installation. – Yury Oct 08 '12 at 15:45
  • Hi Yury, I am able to launch the application through script.Then how the installation problem will come? – user1722227 Oct 09 '12 at 06:33
0

One of the challenges would be to find the coordinates to touch, mainly using different screen sizes and configurations. AndroidViewClient can help in this respect and you can avoid having to provide the coordinates for the Views and you can simply do:

subject = vc.findViewByIdOrRaise('id/subject')
subject.touch()
subject.type('AVCSample')

this lines were taken from one of the AVC examples: email-send.py

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
-2

Do you have space character as part of the text you're trying to enter? Try without space and see if that works. Then, you can figure out how to deal with space.