看看它,它将帮助您进行页面浏览(对于Java客户端5.0.3),它对我来说非常适合。
public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height * anchorPercentage);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * finalPercentage);
new TouchAction(driver).press(startPoint, anchor).waitAction(Duration.ofMillis(duration)).moveTo(endPoint, anchor).release().perform();
}
public static void swipeVertical(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.width * anchorPercentage);
int startPoint = (int) (size.height * startPercentage);
int endPoint = (int) (size.height * finalPercentage);
new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofMillis(duration)).moveTo(anchor, endPoint).release().perform();
}
致电他们:
对于向上滚动:
swipeVertical((AppiumDriver)driver,0.9,0.1,0.5,3000);
向下滚动:
swipeVertical((AppiumDriver)driver,0.1,0.9,0.5,3000);
对于从右到左:
swipeHorizontal((AppiumDriver) driver,0.9,0.01,0.5,3000);
对于从左到右:
swipeHorizontal((AppiumDriver) driver,0.01,0.9,0.5,3000);