如何在appium中向下滚动

How to scroll down in appium

我知道什么时候我想向下滚动到 appium 中的特定元素使用以下 driver.ScrollTo(value);
但是这个值每次都改变并且无法检测到它我不能使用这个值滚动直到找到元素,但是这个元素是我页面中的最后一个元素并且页面中的元素数量在用户和另一个之间改变。
那么,还有其他方法可以向下滚动到页面末尾吗?

使用 xpath 查找元素而不使用值(因为它是动态的)

然后使用该元素滚动,

WebElement element = driver.findElementByXpath("xpath_of_element");
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);

只是 post 那个页面的 DOM..我会给你高效的 xpath 所以即使你的 dom 是动态的定位器也会工作...

scrollToExactscrollTo 方法自 JAVA 客户端版本 4.0.0 (https://github.com/appium/java-client/blob/master/README.md).

您可以使用 UiScrollableUiSelector 及其方法滚动任何页面 (https://developer.android.com/reference/android/support/test/uiautomator/UiScrollable.html)。

JAVA 代码示例(请使用 C# 语法编辑):

@AndroidFindBy (uiAutomator = "new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().textContains(\"Question \"))")

如果你想滚动到页面底部,请创建方法来执行几个步骤来找到页面的最后一个元素,否则你会得到一个错误(找不到元素)

改用触摸操作

TouchAction t = new TouchAction(驱动程序);

     t.longPress(element(source)).moveTo(element(destination)).release().perform();