You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Appium的TouchAction实现快速双击锁定大写键盘?

解决移动键盘双击Shift锁定大写的自动化测试问题
  • 使用TouchAction链式调用合并两次点击
    把两次tap操作放在同一个动作链中执行,Appium会连续处理这两个动作,大幅缩短间隔时间,符合系统双击识别的阈值要求:
TouchAction touchAction = new TouchAction(driver);
int shiftx = 90, shifty = 2174;
PointOption shiftkey = PointOption.point(shiftx, shifty);
// 合并两次tap到同一个perform操作
touchAction.tap(shiftkey).tap(shiftkey).perform();
  • 手动控制两次点击的间隔(如果链式调用仍不生效)
    通过waitAction设置极短的等待时间(建议50-100ms,小于系统双击识别的默认阈值),确保两次点击的间隔在系统认可的范围内:
import java.time.Duration;
import io.appium.java_client.touch.WaitOptions;

TouchAction touchAction = new TouchAction(driver);
int shiftx = 90, shifty = 2174;
PointOption shiftkey = PointOption.point(shiftx, shifty);
touchAction.tap(shiftkey)
           .waitAction(WaitOptions.waitOptions(Duration.ofMillis(50)))
           .tap(shiftkey)
           .perform();
  • 优先使用元素定位代替固定坐标
    固定坐标可能因设备分辨率变化导致点击偏移,改用元素定位获取Shift键的中心位置,确保两次点击都准确命中目标:
import io.appium.java_client.MobileElement;
import org.openqa.selenium.By;

MobileElement shiftElement = driver.findElement(By.id("com.android.inputmethod.latin:id/shift_key"));
TouchAction touchAction = new TouchAction(driver);
PointOption shiftCenter = PointOption.point(shiftElement.getCenter());
touchAction.tap(shiftCenter).tap(shiftCenter).perform();
  • 直接模拟CAPS_LOCK按键事件(更高效的替代方案)
    跳过双击操作,直接发送系统级的大写锁定按键事件,无需依赖点击间隔:
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;

driver.pressKey(new KeyEvent(AndroidKey.CAPS_LOCK));

内容的提问来源于stack exchange,提问作者Mohammed Irfan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 17:13:21