Пример #1
0
  @Test(groups = {"taobao"})
  public void webDriver() {
    driver.get("http://m.taobao.com/");
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
    MobileElement tmall = (MobileElement) driver.findElementByXPath("//div[@id='a6636-1']");
    tmall.swipe(SwipeElementDirection.DOWN, 1000);
    tmall.tap(1, 1000);
    HashMap<String, Integer> tapObject = new HashMap<String, Integer>();
    tapObject.put("x", 120);
    tapObject.put("y", 120);
    tapObject.put("touchCount", 1);
    tapObject.put("duration", 1200);
    driver.executeScript("mobile: tap", tapObject);
    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, Double> flickObject = new HashMap<String, Double>();
    flickObject.put("startX", 200.0);
    flickObject.put("startY", 700.5);
    flickObject.put("endX", 200.2);
    flickObject.put("endY", 100.5);
    js.executeScript("mobile: flick", flickObject);

    TouchAction action = new TouchAction(driver);

    action.press(tmall).waitAction(400).perform();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
    List<WebElement> elements =
        driver.findElementsByXPath("//ul/li/a[@class='card-item card-style-chn']");
    for (WebElement e : elements) {
      System.out.println(e.getAttribute("href"));
    }
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    System.out.println(driver.getPageSource());
  }
  public void iOSSwipe(int startX, int startY, int endX, int endY) throws Exception {
    TouchAction action = new TouchAction(driver);

    action.press(startX, startY);
    action.waitAction(1000); // has to be >= 500 otherwise it will fail
    action.moveTo(endX, endY);
    action.release();
    action.perform();
  }