如何使用Python客户端使用Appium滚动Android应用程序

时间:2018-03-26 07:40:13

标签: android python-3.x selenium-webdriver appium appium-android

我正在测试Android应用程序并需要滚动文本。我已经尝试了我在这里和互联网上找到的所有东西,但没有任何工作。

Appium v​​1.4.1(Server v1.7.2) Python 3.x 使用selenium webdriver

我需要滚动到页面底部,而不是滚动到特定元素

最接近的是

self.driver.execute_script("mobile: scroll", {"direction": "up"}) 

但它不起作用 。 日志是: selenium.common.exceptions.WebDriverException:消息:未知的移动命令"滚动"。仅支持shell命令。

由于

1 个答案:

答案 0 :(得分:0)

对于Android,滚动时有2个不错的选项:

actions = TouchActions(driver) el = driver.find_element_by_id(<id of element you press to start swipe>) action.press(el).move_to(x=100, y=-1000).release().perform()

您还可以更精确地滚动设备的屏幕尺寸:

screen_size = driver.get_window_size()

self.driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().resourceId("<id of scrollable view>")).scrollIntoView(new UiSelector().resourceId("<id of element to scroll to>"))')

您可以阅读更多here