7

嗨,我正在 Android 中使用 APPIUM。我需要做的是明智地滚动列表页面。我试着做以下事情。

    MobileElement element =(MobileElement)driver.findElement(By.className("android.widget.ListView"));
    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, String> scrollObject = new HashMap<>();
    scrollObject.put("direction", "down");
    scrollObject.put("element", ((RemoteWebElement) element).getId());
    js.executeScript("mobile: scrollTo", scrollObject);

这可行,但列表会不断滚动,直到显示最后一个元素。我需要做的是明智地滚动列表页面。

4

2 回答 2

2

这对我有用。

 List<WebElement> list = driver.findElements(By.xpath("//android.widget.TextView[@resource-id='com.imdb.mobile:id/label']"));

 if (list != null && !list.isEmpty()) {
   WebElement bottomElement = list.get(list.size() - 1);
   WebElement topElement = list.get(0);      
   TouchAction touchAction = newTouchAction(driver).press(bottomElement).moveTo(topElement).release();
   touchAction.perform();
   }
于 2017-12-21T10:20:50.027 回答
0

由于它是一个可滚动的列表,如何使用UiScrollable,例如

driver.FindElement(MobileBy.AndroidUIAutomator("new UiScrollable(
    new UiSelector().scrollable(true).instance(0)).scrollIntoView(
    new UiSelector().resourceId(\"" + id + "\").instance(0))"))

更多选项在这里

于 2017-12-13T19:14:33.327 回答