You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS模拟器应用使用TouchAction无法滚动,升级后报错求助

解决iOS模拟器中TouchAction滚动失效的问题

问题原因

升级到Xcode 16 + Appium 2.11.4 + XCUITest 7.27.1后,旧版TouchAction依赖的/touch/perform端点被XCUITest移除,导致接口调用失败——这是新版本环境对W3C标准Actions API的强制迁移要求。

解决方案

1. 迁移至W3C标准ActionChains API

替换原有TouchAction实现,使用Appium推荐的W3C触摸操作方式:

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput

def scroll_by_touch_action(self, startX, startY, endX, endY):
    # 初始化触摸输入设备
    touch_input = PointerInput(interaction.POINTER_TOUCH, "touch")
    actions = ActionChains(self.driver)
    actions.w3c_actions = ActionBuilder(self.driver, mouse=touch_input)
    
    # 模拟触摸滚动流程
    actions.w3c_actions.pointer_action.move_to_location(startX, startY)
    actions.w3c_actions.pointer_action.press()
    actions.w3c_actions.pause(3)  # 对应原wait(3000)的3秒等待
    actions.w3c_actions.pointer_action.move_to_location(endX, endY)
    actions.w3c_actions.pointer_action.release()
    
    actions.perform()

2. 使用Appium内置滚动脚本(更简洁)

如果仅需实现滚动功能,可直接调用iOS专属的mobile: scroll脚本,无需手动构建触摸链:

def scroll_by_appium_api(self, startX, startY, endX, endY):
    self.driver.execute_script("mobile: scroll", {
        "startX": startX,
        "startY": startY,
        "endX": endX,
        "endY": endY,
        "duration": 3.0  # 滚动持续时间(秒)
    })

额外兼容检查

  • 执行appium driver update xcuitest将XCUITest驱动更新至与Xcode 16兼容的最新版本
  • 确保Appium服务默认启用W3C模式(无需手动修改配置,默认已开启)

内容的提问来源于stack exchange,提问作者Sharique Alam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 09:10:19