如何在appium中向下滚动

时间:2016-02-06 10:49:07

标签: c# automation appium

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

3 个答案:

答案 0 :(得分:0)

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

然后使用该元素滚动

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

只需发布该页面的DOM ..我将为您提供高效的xpath,即使您的dom是动态的,定位器也能正常工作......

答案 1 :(得分:0)

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

scrollToExactscrollTo方法已被删除。

您可以使用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   \&#34))&#34)

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

答案 2 :(得分:0)

改为使用触摸操作

TouchAction t =新的TouchAction(驱动程序);

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