其他分享
首页 > 其他分享> > android-如何在Uiautomator中实现长按

android-如何在Uiautomator中实现长按

作者:互联网

我正在尝试编写代码以连拍模式捕获图片,这需要在“捕获”按钮上长按(约一分钟),如何实现?

UiObject CameraButton = new UiObject(new UiSelector().text("Capture"));
        CameraButton.longClick();

longclick():将按住按钮多少时间?是否可以执行带有时间戳的长按.

解决方法:

使用滑动(int startX,int startY,int endX,int endY,int步骤)对您想要的时间执行长按.最后一个参数步骤确定时间. For a 100 steps, the swipe will take about 1/2 second to complete.步骤的值越大,单击和释放的时间越长.

UiObject CameraButton = new UiObject(new UiSelector().text("Capture"));
Rect CameraButton_rect = CameraButton.getBounds();
getUiDevice().swipe(CameraButton_rect.centerX(), CameraButton_rect.centerY(), CameraButton_rect.centerX(), CameraButton_rect.centerY(), 100);

标签:uiautomator,button,click,ui-automation,android
来源: https://codeday.me/bug/20191122/2057711.html