如何从APPIUM中的脚本滚动列表

问题描述 投票:7回答:2

嗨,我在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);

这可以工作,但列表会连续滚动,直到显示最后一个元素。我需要做的是明智地滚动列表页面。

android listview scroll appium appium-android
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();
   }

0
投票

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

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

更多选择here

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.