跳至主要內容

touchAction

棄用警告

touchAction 指令已棄用,並將在未來版本中移除。我們建議改用帶有指標類型 touchaction 指令,例如:

await browser.action('pointer', {
parameters: { pointerType: 'touch' }
})

觸控動作 API 提供了在 Appium 中可以自動化的所有手勢的基礎。目前它僅適用於原生應用程式,不能用於與 Web 應用程式互動。其核心是將單個臨時動作鏈接在一起的能力,然後將其應用於裝置上應用程式中的元素。可以使用的基本動作有:

  • press(傳遞元素或 (x,y) 或兩者)
  • longPress(傳遞元素或 (x,y) 或兩者)
  • tap(傳遞元素或 (x,y) 或兩者)
  • moveTo(傳遞絕對 x,y 座標)
  • wait(傳遞毫秒 (以毫秒為單位))
  • release(沒有參數)
用法
$(selector).touchAction(action)
參數
名稱類型詳細資訊
actionTouchActions要執行的動作
範例
touchAction.js
it('should do a touch gesture', async () => {
const screen = await $('//UITextbox');

// simple touch action on element
await screen.touchAction('tap');

// simple touch action using selector and x y variables
// tap location is 30px right and 20px down relative from the center of the element
await screen.touchAction({
action: 'tap', x: 30, y:20
})

// multi action on an element (drag&drop)
await screen.touchAction([
'press',
{ action: 'moveTo', x: 200, y: 300 },
'release'
])

// drag&drop to element
const otherElement = await $('//UIAApplication[1]/UIAElement[2]')
await screen.touchAction([
'press',
{ action: 'moveTo', element: otherElement },
'release'
])
});

歡迎!我能如何幫您?

WebdriverIO AI Copilot