Przejdź do głównej treści

longPress

Wykonuje gest długiego naciśnięcia na danym elemencie na ekranie.

Polecenie to wydaje komendę WebDrivera action dla wybranego elementu. Bazuje ono na komendzie click.

informacja

Ta komenda działa tylko z następującymi aktualnymi komponentami:

  • Serwer Appium (wersja 2.0.0 lub wyższa)
  • appium-uiautomator2-driver (dla Androida)
  • appium-xcuitest-driver (dla iOS)

Upewnij się, że Twoje lokalne lub chmurowe środowisko Appium jest regularnie aktualizowane, aby uniknąć problemów z kompatybilnością.

Użycie
$(selector).longPress({ x, y, duration })
Parametry
NazwaTypSzczegóły
options
opcjonalny
LongPressOptionsOpcje długiego naciśnięcia (opcjonalne)
options.x
opcjonalny
numberLiczba (opcjonalna)
options.y
opcjonalny
numberLiczba (opcjonalna)
options.duration
opcjonalny
numberCzas trwania naciśnięcia w ms, domyślnie 1500 ms
TYLKO DLA URZĄDZEŃ MOBILNYCH
Przykłady
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