&引用;“拉动以刷新”;与appium一起使用SeleniumWebDriver和java for android
如何使用selenium webdriver和java在android应用程序屏幕上使用appium编写“Pull to Refresh”脚本只需围绕selenium appium中内置的滑动功能创建一个包装器即可。模拟类似于用户活动的功能&引用;“拉动以刷新”;与appium一起使用SeleniumWebDriver和java for android,android,eclipse,selenium,appium,Android,Eclipse,Selenium,Appium,如何使用selenium webdriver和java在android应用程序屏幕上使用appium编写“Pull to Refresh”脚本只需围绕selenium appium中内置的滑动功能创建一个包装器即可。模拟类似于用户活动的功能 public static void swipeDown(AppiumDriver driver) throws InterruptedException { Dimension size = driver.manage().window().g
public static void swipeDown(AppiumDriver driver) throws InterruptedException
{
Dimension size = driver.manage().window().getSize();
System.out.println(size);
//Find swipe start and end point from screen's with and height.
//Find starty point which is at bottom side of screen.
int starty = (int) (size.height * 0.80);
//Find endy point which is at top side of screen.
int endy = (int) (size.height * 0.65);
//Find horizontal point where you wants to swipe. It is in middle of screen width.
int startx = size.width / 2;
System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx);
//Swipe from Bottom to Top.
driver.swipe(startx, endy, startx, starty, 1000);
Thread.sleep(200);
}
请根据您的需要更改刷卡起点和终点
希望这对你有帮助。谢谢。使用这段代码,只需创建简单的枚举方向,包括上、下、右、左的值 提供向下键,并输入执行刷卡的时间
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();
}
您使用的是哪个appium,java客户端?在最新版本的appium(我使用的是1.15)中,滑动不再有效