此方法已被弃用,因为它不一致并且将被删除。这实际上是一种解决方法。
建议改用:
AppiumDriver.swipe(int, int, int, int, int)
MobileElement.swipe(SwipeElementDirection, int)
MobileElement.swipe(SwipeElementDirection, int, int, int)
或使用
搜索元素
MobileBy.ByAndroidUIAutomator
指定者:
scrollTo in interface ScrollsTo<org.openqa.selenium.WebElement>
参数:
text - 元素的描述或文本滚动到
回报:
匹配的元素
现在给用户swipe
public abstract void swipe(int startx, int starty, int endx, int endy, int duration)
从界面复制的描述:
触控快捷键
在屏幕上滑动的便捷方法。
参数:
startx - 起始 x 坐标。
starty - 起始 y 坐标。
endx - 结束 x 坐标。
endy - 结束 y 坐标。
持续时间 - 整个滑动操作的时间量(以毫秒为单位)
示例:
@Test
public void swipingVertical() throws InterruptedException {
//Get the size of screen.
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.20);
//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, starty, startx, endy, 3000);
Thread.sleep(2000);
//Swipe from Top to Bottom.
driver.swipe(startx, endy, startx, starty, 3000);
Thread.sleep(2000);
}
这肯定适用于新版本的 Java Client 4.0 来执行您的 Appium 脚本
问候:
高拉夫小伙子