Clear Edit Text - adb
Solution 1
This works for me:
function clear_input() {
adb shell input keyevent KEYCODE_MOVE_END
adb shell input keyevent --longpress $(printf 'KEYCODE_DEL %.0s' {1..250})
}
Then:
clear_input
Solution 2
If you use uiautomator(https://github.com/xiaocong/uiautomator), you could do this by:
tap the EditText widget to get focus, then
use
device(focused=True).clear_text()
to clear the view, or bydevice(focused=True).set_text("new text")
to set a new text.
Solution 3
The only way that I have found so far is to get the proper coordinates to use input swipe x y x y duration
to simulate a long press. This will then highlight all the text in the EditText field. You can then send the keys you want to replace what was there.
I just wish that adb shell input keyevent KEYCODE_CLEAR
would clear all the text in the field. That would make things so much easier, if someone can find a better way that would be great.
Krishnakant
Expertise in Android Application Development using Eclipse IDE, Android Studio, Java, XML, JSON, Android SDK and ADT plug-in. Proficient with common Android framework APIs Adequate experience in Mobile Development Life Cycle from concept to delivery, object oriented analysis and design methodologies. Deep knowledge of Android SDK and working on client-server architecture in mobile apps. Successfully developed different component to reduce time and effort of my teammates in coding the application. Hands on knowledge of Android TV SDK, DIAL Protocol implication, SetupBox apps implementation, Leanback API's, Global Search Implementation, Customize TV launcher. Excellent in troubleshooting / debugging. Prior experience of working in Agile environment. By doing R&D, Innovates new ideas and discuss with colleagues trying to create dynamic Environment at work place.
Updated on June 14, 2022Comments
-
Krishnakant almost 2 years
How to clear focused Edit text using shell command.
I tried
adb shell input keyevent KEYCODE_CLEAR // Not worked adb shell input keyevent KEYCODE_DEL // Delete only one char adb shell input keyevent KEYCODE_FORWARD_DEL // Not worked
With this I am only able to delete upto One character only, Is there any way I can delete/clear the focused Edit text.