Actually I want to delete all text in a text field, and I am using a loop calling device.press('KEYCODE_DEL')
to achieve this.
But there are two disadvantages:
- Not efficient enough, especially when I don't know how many characters in the text field so I need set a large enough loop
- Need to move the cursor to the end before deleting
So I am trying to accomplish this by two steps:
- select all text
- press delete button
I found an similar question here which is not solved yet.
And there is an answer for how to select all text, but I think it has the same issues as my loop delete way.
I did several tests, and found a way close to it:
device.press('KEYCODE_MENU', 'MonkeyDevice.DOWN', '')
device.press('KEYCODE_A')
device.press('KEYCODE_MENU', 'MonkeyDevice.UP', '')
I thought these three steps accomplish a MENU+A
operation. But it did not work every time. I executed this code for 20 times(in a loop) and found it only took effect for about 5-8 times.
Besides, I found these three steps will move the cursor to the first place most of the time.
Did anyone know why is this operation not reliable? Or any other suggestions to select all text?
Appreciate for any suggestions!