0

场景是在一个框上从右向左滑动。你会得到一些动态的结果。并验证它们。

4

1 回答 1

0

U can Identify locators for 2 elements -

1 - Element till where u want to reach

2 - A Common Xpath for All Horizontal Elements in that box and run following code to Scroll Horizontally.

public static void scrollTillElementHorizontally(By by, By allElements) {
    if (driver.findElements(By) > 0 || driver.findElement(By).isDisplayed())
        return;

    int y = driver.findElement(allElements).getCenter().y;
    int width = driver.manage().window().getSize().getWidth();
    double startX = width * 0.80;
    double endX = width * 0.20;
    TouchAction action = new TouchAction(driver);
    int i = 0;
    while (i < 50) {
        if (driver.findElements(By) > 0 || driver.findElement(By).isDisplayed())
            break;
        action.press(PointOption.point((int) startX, y)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2)))
                .moveTo(PointOption.point((int) endX, y)).release().perform();
        i++;
    }
}

And if u want to remove duplicate elements while scrolling add the elements to HashSet which would remove duplicates while scrolling.

于 2019-01-25T05:21:18.667 回答