我想使用 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)
这也会滚动列表,但滚动时间很长,但我想转到列表中的每个元素。
谁能告诉我如何滚动列表一次?
最佳答案
我尝试了下面提到的代码并且非常适合我想要的代码。我只是使用了像按下和释放这样的触摸 Action ,因为我想滚动一次,所以从中删除 release() 部分然后它对我来说非常有效:)
el1 = self.driver.find_element_by_xpath("<xpath>")
el2 = self.driver.find_element_by_xpath("<xpath>")
action = TouchAction(self.driver)
action.press(el1).move_to(el2).perform()
还有谁想要相同的,他/她可以使用相同的基础知识。
关于android - 如何使用 Appium 和 Python 在 Android 应用程序中滚动列表一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36998858/