python - 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 中的触摸操作中遇到问题
任何人都可以帮助我吗?提前致谢。
解决方案
它应该是这样的:
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()
推荐阅读
- java - 如何为 Android Room 请求制作通用 AsyncTask
- javascript - 设置自定义 HTML 元素的内容
- php - 计算一个键在数组一侧的对象中有多少次 ans="true"
- python - 没有错误产生,但数据库中的记录没有更新
- sql - 不同表上同名的列可以有不同的数据类型吗?
- vuejs2 - 在 vuex 状态下更改元主题颜色
- google-bigquery - 使用两个自定义 Firebase 参数作为维度在 Data Studio 中创建图表
- sql-server - 如何在 CASE 中的 WHEN 中使用多个条件
- c# - System.Net.Http.HttpRequestException 仅在第一次调用时将内容复制到流时出错
- angular - mediaStream 和 Angular 4 中的“元素”类型上不存在属性“scr”