Hello guyz,
I was also stuck in scroll page issue today in my appium automation. i am using robot framework with appium library and running my automation real device using adb service.
i first tried using the appiumlibrary keywords Scroll ¡ Scroll Down ¡ Scroll Up but was getting error as
" WebDriverException: Message: Unknown mobile command âscrollâ. Only shell,startLogsBroadcast,stopLogsBroadcast commands are supported. "
then i tried implementing custom keywords using scroll methods via java & python code also but got the same error as above.
i even tried to use scroll up/down keywords of Androidlibrary of robot framework but it didânt worked due import error as below:
Importing test library âAndroidLibraryâ failed: ImportError: cannot import name GLOBAL_VARIABLES
then finally i came up with 2 ways to scroll element as below:
-
def scroll_page_to_text(self,text):
driver = self.get_appium_webdriver_instance()
driver.implicitly_wait(5000)
element = driver.find_element_by_android_uiautomator(ânew UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className(âandroid.widget.TextViewâ), "â
+ text + â")â)
this i found on stackoverflow and worked for me
-
if for some reasons the above didânt work then use this alternative way of drag drop element. this is not good way but yes youâll not be blocked atleast till you find a better way.
def scroll_page_down(self,source_element_locator,destn_element_locator):
driver = self.get_appium_webdriver_instance()
driver.implicitly_wait(5000)
source_element=driver.find_element_by_xpath(source_element_locator)
destn_element=driver.find_element_by_class_name(destn_element_locator)
driver.drag_and_drop(source_element,destn_element)
this will work even if yours elements are not actually draggable/droppable. just make sure to pass locator of lowermost element of current screen as source_element_locator, then any element locator which is on top of screen as destn_element_locator. driver.drag_and_drop method will try to drag source_element to destn_element and it will automatically scroll your screen.