切片编辑文本-ADB

问题描述 投票:0回答:6

如何使用shell命令清除专注的编辑文本。 我尝试了

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

我只能仅删除一个字符,有什么办法可以删除/清除专注的编辑文本。
    

这对我有用:
android adb android-framework android-shell
6个回答
18
投票
function clear_input() { adb shell input keyevent KEYCODE_MOVE_END adb shell input keyevent --longpress $(printf 'KEYCODE_DEL %.0s' {1..250}) }

到达:
clear_input

这将选择全部,然后选择返回。

6
投票

您可以使用这种方式:
adb shell input keyevent --longpress 67 67 67 67 67 67 67 67 67 67 67 67 67 67 67 67 67 67

4
投票
67是

Keycode_del

的键代码
    

如果您使用uiautomator(https://github.com/xiaocong/uiautomator

),则可以通过:

2
投票
top topedext小部件以获取焦点,然后

使用
    device(focused=True).clear_text()
  1. 清除视图,或者通过

    device(focused=True).set_text("new text")

    设置新文本。
  2. 
    
    到目前为止,我发现的唯一方法是使适当的坐标用于模拟长压力。然后,这将突出显示EditText字段中的所有文本。然后,您可以发送要替换那里的键。
    
    
    我只是希望

    input swipe x y x y duration
  3. 能清除字段中的所有文本。如果有人能找到一种更好的方法,那将使事情变得更加容易。

1
投票
这对我有用:

the Phone Text Field上的光标cobus for

adb shell input keyevent KEYCODE_CLEAR



0
投票

    driver.execute_script('mobile: pressKey', { keycode: 29, metastate: 4096 }) # KEYCODE_A with META_CTRL_ON

输入新电话号码:


    driver.execute_script('mobile: pressKey', { keycode: 67 }) # KEYCODE_DEL

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.