JavascriptExecutor js = (JavascriptExecutor) driver;
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);
JavascriptExecutor js = (JavascriptExecutor) driver; 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););
3.scroll操作,专为iOS 7.x而生,官方的解释如下
An unfortunate bug exists in the iOS 7.x Simulator where ScrollViews don't recognize gestures initiated by UIAutomation (which Appium uses under the hood for iOS). To work around this, we have provided access to a different function, scroll, which in many cases allows you to do what you wanted to do with a ScrollView, namely, scroll it!
JavascriptExecutor js = (JavascriptExecutor) driver; HashMap<String, String> scrollObject = new HashMap<String, String>(); scrollObject.put("direction", "right"); js.executeScript("mobile: scroll", scrollObject
3.云阅读,云阅读的引导图并不是存在于ScrollView中,而是专门有一个UIAElement存放,那就只需要用swipe拖动这个UIAElement就好了,如图所示。JavascriptExecutor js = (JavascriptExecutor) driver; WebElement element = driver.findElementByXPath("4张image的xpath路径"); HashMap<String, String> scrollObject = new HashMap<String, String>(); scrollObject.put("element", ((RemoteWebElement) element).getId()); js.executeScript("mobile: scroll", scrollObject);