简体   繁体   中英

How to scroll Android app with Appium by Python Client

I'm testing Android application and need to scroll text. I have tried everything I found here and on a Internet but nothing is working.

Appium v1.4.1 (Server v1.7.2) Python 3.x Using selenium webdriver

I need scroll to the bottom of a page, not to specific element

The closest is

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

but it is not working . Log is: selenium.common.exceptions.WebDriverException: Message: Unknown mobile command "scroll". Only shell commands are supported.

Thanks

For Android there are 2 good options when it takes to scrolling:

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()

You can also get screen size of the device to scroll more precisely:

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>"))')

You can read more here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM