跳到主要内容

长按

在屏幕上对给定元素执行长按手势。

这会为选定元素发出WebDriver的action命令。它基于click命令。

信息

此命令仅适用于以下最新组件:

  • Appium服务器(版本2.0.0或更高)
  • appium-uiautomator2-driver(用于Android)
  • appium-xcuitest-driver(用于iOS)

确保定期更新您的本地或基于云的Appium环境,以避免兼容性问题。

用法
$(selector).longPress({ x, y, duration })
参数
名称类型详情
options
可选
LongPressOptions长按选项(可选)
options.x
可选
number数字(可选)
options.y
可选
number数字(可选)
options.duration
可选
number按压持续时间(毫秒),默认为1500毫秒
仅适用于移动设备
示例
longpress.offset.js
it('should demonstrate a longPress using an offset on the iOS Contacts icon', async () => {
const contacts = $('~Contacts')
// opens the Contacts menu on iOS where you can quickly create
// a new contact, edit your home screen, or remove the app
// clicks 30 horizontal and 10 vertical pixels away from location of the icon (from center point of element)
await contacts.longPress({ x: 30, y: 10 })
})

longpress.example.js
it('should be able to open the contacts menu on iOS by executing a longPress of 5 seconds', async () => {
const contacts = $('~Contacts')
// opens the Contacts menu on iOS where you can quickly create
// a new contact, edit your home screen, or remove the app
await contacts.longPress({ duration: 5 * 1000 })
})

Welcome! How can I help?

WebdriverIO AI Copilot