作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
有以下两种方法:-
方法 1(使用 TouchActions):-
1. //Swipe Right to Left side of the Media Viewer First Page
WebElement firstPages = driver.findElement(By.id("media-list"));
TouchActions flick = new TouchActions(driver).flick(firstPages,-100,0,0);
flick.perform();
2. //perform swipe gesture
TouchActions swipe = new TouchActions(driver).flick(0, -20);
swipe.perform();
方法 2(使用 javascript):-
public static void swipe(WebDriver driver) {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> swipeObject = new java.util.HashMap<String, Double>();
swipeObject.put("startX", 0.95);
swipeObject.put("startY", 0.5);
swipeObject.put("endX", 0.05);
swipeObject.put("endY", 0.5);
swipeObject.put("duration", 1.8);
js.executeScript("mobile: swipe", swipeObject);
}
最佳答案
尝试以下实现,其中包括标准 FlickAction.SPEED_NORMAL 参数以及 flick 的 Action 生成器:
import org.openqa.selenium.interactions.touch.FlickAction;
private Action getBuilder(WebDriver driver) {
return new Action(driver);
}
WebElement toFlick = driver().findElement(By.id("media-list"));
Action flick = getBuilder(driver()).flick(toFlick, -500, 0, FlickAction.SPEED_NORMAL).build();
flick.perform();
可以通过改变 X 轴坐标来执行从左向右滑动和反之亦然:
Action flick = getBuilder(driver()).flick(toFlick, -500, 0, FlickAction.SPEED_NORMAL).build();
Action flick = getBuilder(driver()).flick(toFlick, 500, 0, FlickAction.SPEED_NORMAL).build();
Action flick = getBuilder(driver()).flick(toFlick, 0, 500, FlickAction.SPEED_NORMAL).build();
Action flick = getBuilder(driver()).flick(toFlick, 0, -500, FlickAction.SPEED_NORMAL).build();
关于java - 如何在 Selendroid 中执行滑动操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29210824/
我是一名优秀的程序员,十分优秀!