如何使用硒的滑动功能

时间:2016-09-02 09:42:19

标签: java selenium-webdriver appium

我必须使用文章ID轻扫一些文章,但每刷新一篇文章后就有一则广告,我该如何管理它。而且我也必须打印文章的名称。我使用了以下代码

    ...
    System.out.println(driver.manage().window().getSize().getWidth());
    System.out.println(driver.manage().window().getSize().getHeight());

    int screenWidth = driver.manage().window().getSize().getWidth();
    int screenHeight = driver.manage().window().getSize().getHeight();
    try {
        element = driver.findElements(By.id("templeconnect.com.templeconnect:id/templetitle"));
    } catch (NoSuchElementException e) {
        System.out.println("no such element");
    }

    //swipe up
    startx = screenWidth / 2;
    endx = screenWidth / 2;
    starty = screenHeight * 6 / 7;
    endy = screenHeight / 7;
    driver.swipe(startx, starty, endx, endy, 2000);
    Thread.sleep(3000);
    myfun(element);

}

public void myfun(List<WebElement> element) {
    try {
        System.out.println(element.size());
        for (WebElement webElement : element) {
            System.out.println(webElement.getText());
            if (webElement.getText().equals("")) {
            } else {
                driver.swipe(startx, starty, endx, endy, 2000);
                Thread.sleep(3000);
                myfun(element);
            }
        }
    } catch (NoSuchElementException e) {
        System.out.println("no such element my funtion");
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public void myfun1(List<WebElement> element1) throws InterruptedException {
    for (WebElement webElement1 : element1) {
        System.out.println(webElement1.getText());
        if (webElement1.getText().equals("EXPLORE MORE")) {
            driver.swipe(startx, starty, endx, endy, 2000);
        }
    }
}

0 个答案:

没有答案