首页 > 解决方案 > AttributeError:模块“appium.webdriver”没有属性“TouchActions”

问题描述

我尝试使用 Appium 中的 TouchActions 执行水平横幅滑动,但收到错误消息:

AttributeError: module 'appium.webdriver' has no attribute 'TouchActions'

代码:

wait = WebDriverWait(driver, 15)
element = wait.until(EC.visibility_of_element_located((By.ID, 'com.project.ProjectName:id/bannersRecyclerView')))
# swipe right = dx: -992.0 dy: 11.0
# swipe left = dx: 992.0 dy: 11.0
action = webdriver.TouchActions(driver)
action.press(x=-992, y=11).move_to(x=0, y=-11).release().perform()

从导入的模块:

from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.touch_actions import TouchAction

可能类似于:在使用 python 的 appium 中的触摸操作中遇到问题

任何人都可以帮助我吗?提前致谢。

标签: pythonandroidseleniumgesture-recognition

解决方案


它应该是这样的:

from appium.webdriver.common.touch_action import TouchAction

检查您的代码是否是最新版本的Appium Python 客户端

但是,您也可以尝试不同的方法,因为它看起来像是 W3C 操作的包装器:Actions

有很多方法可以解决这个问题,我建议您不要对坐标进行硬编码,特别是如果您要自动进行水平横幅滑动。

尝试使用该特定横幅的 id 或类似定位器。

行动方式

element = driver.find_element_by_accessibility_id(banner_id)
actions = ActionChains(driver)
actions.move_to_element(element)
actions.click_and_hold(element)
actions.move_by_offset(xoffset,yoffset)
actions.release()
actions.perform()

触摸动作.md


推荐阅读