Android 如何在Uiautomator中实现长点击
我正在尝试编写一个代码以突发模式捕获图片。这需要长时间单击捕获按钮(大约一分钟)。如何实现这一点Android 如何在Uiautomator中实现长点击,android,button,click,ui-automation,android-uiautomator,Android,Button,Click,Ui Automation,Android Uiautomator,我正在尝试编写一个代码以突发模式捕获图片。这需要长时间单击捕获按钮(大约一分钟)。如何实现这一点 UiObject CameraButton = new UiObject(new UiSelector().text("Capture")); CameraButton.longClick(); longclick():它将按住按钮多少时间?是否可以使用时间戳执行长时间单击。使用滑动(int-startX、int-startY、int-endX、int-endY、int-steps
UiObject CameraButton = new UiObject(new UiSelector().text("Capture"));
CameraButton.longClick();
longclick():它将按住按钮多少时间?是否可以使用时间戳执行长时间单击。使用滑动(int-startX、int-startY、int-endX、int-endY、int-steps)执行长时间单击。最后一个参数步数确定时间。步长值越大,单击和释放的持续时间越长
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);
另一个选项是将对象转换为自身:
UiObject CameraButton = new UiObject(new UiSelector().text("Capture"));
CameraButton.dragTo(CameraButton, 10);
根据所需时间选择步骤。如果您使用的是UIAutomator2,从版本v18:2.1.3开始-
此长时间单击处理通过单击等待时间简化。
/** Performs a click on this object that lasts for {duration} milliseconds. */
public void click(long duration)
希望这对别人有帮助 对于UIautomator 2.0,您应该这样尝试:
BySelector selector = By.res("resourceID");
UiObject2 obj = mDevice.findObject(selector);
Point pot = obj.getVisibleCenter();
mDevice.swipe(pot.x, pot.y, pot.x, pot.y, 200);