Appium-Python-client TouchAction 类正在弃用。我如何执行 press()、long_press() 操作?

问题描述 投票:0回答:1

我有一种方法可以让我在菜单上向下滚动(android 和 iOS)(这对我有用,因为它是一个侧面菜单)。

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

如何通过

ActionChains
的坐标执行按下(或单击?),以便我可以按自定义距离执行向下滚动?

TouchAction
类被弃用,文档建议使用
ActionChains
。我尝试使用同类产品中提供的
ActionChain.some_actions()
来做到这一点,但它们都不适合我。例如:
scroll_to_element()
scroll_by_amount()
scroll_from_origin()
因为它们被导入为:

from selenium.webdriver.common.action_chains import ActionChains

与使用 TouchActions 相反:

from appium.webdriver.common.touch_action import TouchAction

selenium-webdriver appium ui-automation python-appium
1个回答
0
投票

毕竟我自己弄明白了... 所以它似乎必须导入其他几个部分才能模仿 Appium 中的

TouchActions
正在做的事情(荒谬)。所以下面的代码块可以使用 Appium 自动化中即将弃用的
TouchAction
替换我之前的代码块。

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()
© www.soinside.com 2019 - 2024. All rights reserved.