gpt4 book ai didi

java - 如何使用appium水平滑动

转载 作者:行者123 更新时间:2023-12-01 19:53:23 26 4
gpt4 key购买 nike

# screen unable to swipe

我有 5 个滑动屏幕,我的代码只是停留在第三个屏幕上,我想水平滚动。

最佳答案

以下代码已被证明对我有用:

enum DIRECTION{UP, DOWN, LEFT, RIGHT};

和:

public static void swipe(MobileDriver driver, DIRECTION direction, long duration) {
Dimension size = driver.manage().window().getSize();

int startX = 0;
int endX = 0;
int startY = 0;
int endY = 0;

switch (direction){
case RIGHT:
startY = (int) (size.height /2);
startX = (int) (size.width * 0.90);
endX = (int) (size.width * 0.05);
break;

case LEFT:
startY = (int) (size.height /2);
startX = (int) (size.width * 0.05);
endX = (int) (size.width * 0.90);
break;

case UP:
endY= (int) (size.height * 0.70);
startY = (int) (size.height * 0.30);
startX = (size.width / 2);
break;


case DOWN:
startY = (int) (size.height * 0.70);
endY = (int) (size.height * 0.30);
startX = (size.width / 2);

break;

}

new TouchAction(driver)
.press(startX, startY)
.waitAction(Duration.ofMillis(duration))
.moveTo(endX, startY)
.release()
.perform();

}

希望对你有帮助...

关于java - 如何使用appium水平滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50504087/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com