问题
I am trying to delete text from a text field using monkeyrunner API . I am writing script in python.
There are key events like " KEYCODE_FORWARD_DEL","KEYCODE_DEL" and to move the cursor to the end "KEYCODE_MOVE_END".
I am trying to delete text, for this, I tried to move the cursor to the end but"KEYCODE_MOVE_END" did not work. Cursor did not move at all.
Then, I tried to use " KEYCODE_FORWARD_DEL" but it also did not work.
These, keys are working for the text field in which I entered text using my script, but these are not working for the fields, which were already filled.
Can any one, please guide me?
回答1:
This worked for me, though haven't tried setting a Exchange account:
fieldLength = 50
# select all the chars
self.device.press('KEYCODE_SHIFT_LEFT', MonkeyDevice.DOWN)
for i in range(fieldLength):
self.device.press('KEYCODE_DPAD_LEFT', MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(1)
self.device.press('KEYCODE_SHIFT_LEFT', MonkeyDevice.UP)
# delete them
self.device.press('KEYCODE_DEL', MonkeyDevice.DOWN_AND_UP)
来源:https://stackoverflow.com/questions/12493101/how-to-delete-text-from-a-text-field-using-monkeyrunner-api-python-script