Appium 滑动:
有三种方式:
第一种:swipe
- JavascriptExecutor js = (JavascriptExecutor) driver;
- WebElement element = driver.findElementByXPath("xpath");
- HashMap<String, Double> swipeObject = new HashMap<String, Double>();
- swipeObject.put("startX", startX);
- swipeObject.put("startY", startY);
- swipeObject.put("endX", endX);
- swipebject.put("endY", endY);
- swipeObject.put("duration", duration);
- swipeObject.put("element", Double.valueOf(((RemoteWebElement) element).getId()));
- js.executeScript("mobile: swipe", swipeObject);
X,Y可为coordinator,也可以是percent,大于1 为coordinator, 小于1 为percent,比如0.5 代表50%
duration单位为秒, Android 可以设置0.1-60,iOS设置0.5-60
需要滑动特定的对象时需要指定的element,只是在名目上滑动式就可以不指定element
第二种: flick 区别swipe是没有duration
- JavascriptExecutor js = (JavascriptExecutor) driver;
- WebElement element = driver.findElementByXPath("xpath");
- HashMap<String, Double> flickObject = new HashMap<String, Double>();
- flickObject.put("startX", 0.8);
- flickObject.put("startY", 0.5);
- flickObject.put("endX", 0.2);
- flickObject.put("endY", 0.5);
- flickObject.put("element", Double.valueOf(((RemoteWebElement) element).getId()));
- js.executeScript("mobile: flick", flickObject);
第三种: scroll only for iOS scrollViewscroll方向滑动:
- JavascriptExecutor js = (JavascriptExecutor) _driver;
- HashMap<String, String> scrollObject = new HashMap<String, String>();
- scrollObject.put("direction", sDrection);
- js.executeScript("mobile: scroll", scrollObject);
方向接受参数:Right, Left, Up, Down
重要:方向和我们认为的方向相反,比如要向下滑,就用Up,应为Up的意思是滑动到手机的顶部,左右也是一样,左滑就是Right
scroll对象滑动:
- JavascriptExecutor js = (JavascriptExecutor) driver;
- WebElement element = driver.findElementByXPath("scrollview中元素的xpath");
- HashMap<String, String> scrollObject = new HashMap<String, String>();
- scrollObject.put("element", ((RemoteWebElement) element).getId());
- js.executeScript("mobile: scroll", scrollObject);