1

I have a method that allows me to scroll down (android and iOS) on a menu (this works for me since it's a side menu).

from appium.webdriver.common.touch_action import TouchAction

    def _scroll_down_menu_settings(self, distance=400):
        action = TouchAction(self.driver)
        window_size = self.driver.get_window_size()
        x, y = window_size['width'] / 6, window_size['height'] / 2
        action.press(x=x, y=y).wait(500).move_to(x=x, y=y - distance).release().perform()

How can I perform a press (or click?) by coordinates with ActionChains so I can perform a scroll down by customized distance?

TouchAction class is being deprecated, and the documentation recommends to use ActionChains. I've tried to do it with ActionChain.some_actions() available in its class, but none of them work for me. For example: scroll_to_element(), scroll_by_amount(), scroll_from_origin() since they are imported as:

from selenium.webdriver.common.action_chains import ActionChains

as opposed to using TouchActions as:

from appium.webdriver.common.touch_action import TouchAction

1 Answers1

2

I figured it out myself after all... So It seems it has to import several other parts in order to mimic what TouchActions from Appium was doing (ridiculous). So below is the block of code that can replace my previous block of code using the soon-to-be deprecated TouchAction in Appium automation.

def _scroll_down_menu_settings(self, distance=400):
    action = ActionChains(self.driver)
    window_size = self.driver.get_window_size()
    x, y = window_size['width'] / 6, window_size['height'] / 2
    action.w3c_actions = ActionBuilder(self.driver, mouse=PointerInput(interaction.POINTER_TOUCH, 'touch'))
    action.w3c_actions.pointer_action.move_to_location(x, y)
    action.w3c_actions.pointer_action.click_and_hold()
    action.w3c_actions.pointer_action.move_to_location(x, y - distance)
    action.w3c_actions.pointer_action.release()
    action.w3c_actions.perform()