【发布时间】:2016-08-28 04:29:44
【问题描述】:
我想使用 Python 滚动到 Android 应用程序中的列表,以下代码对我有用:
self.driver.find_element_by_android_uiautomator('new UiScrollable(newUiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("India").instance(0));')
但这会滚动列表,直到它不在印度,但我只想滚动一次。
我也试过这个:
el1 = self.driver.find_element_by_xpath("//*[@resource-id = 'resource-id' and @index ='1']")
el2 = self.driver.find_element_by_xpath("//*[@resource-id = 'resource-id' and @index ='0']")
self.driver.scroll(el1, el2)
这也滚动列表,但它正在做一个长滚动,但我想去列表中的每个元素。
谁能告诉我如何滚动列表一次?
【问题讨论】:
-
不确定
scrollIntoView(new UiSelector().text("India")是如何工作的,但您能否尝试在列表中查找第二个元素的文本并执行与scrollIntoView(new UiSelector().text("<text of 2nd element>")相同的操作 -
我尝试了这个并且完美地为我工作,我只是使用了像按下和释放这样的触摸动作,因为我想滚动一次,所以从中删除 release() 部分然后它工作非常适合我 :) el1 = self.driver.find_element_by_xpath("
") action = TouchAction(self.driver) action.press(el1).move_to(el2 ).perform() 还有谁想要一样的,他/她可以使用相同的基本原理。 -
如果是这种情况,您可以自己分享它作为这个问题的答案。
标签: android python selenium appium vertical-scrolling