longPress
Виконує жест довгого натискання на заданому елементі на екрані.
Ця команда видає WebDriver команду action
для вибраного елемента. Вона базується на команді click
.
інфо
Ця команда працює лише з наступними актуальними компонентами:
- Appium server (версія 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 })
})