Zum Hauptinhalt springen

waitForExist

Warte die angegebene Anzahl von Millisekunden, bis ein Element im DOM vorhanden ist. Gibt true zurück, wenn der Selektor mindestens ein Element findet, das im DOM existiert, ansonsten wird ein Fehler ausgelöst. Wenn das reverse-Flag auf true gesetzt ist, gibt der Befehl stattdessen true zurück, wenn der Selektor keine Elemente findet.

Info

Im Gegensatz zu anderen Elementbefehlen wartet WebdriverIO nicht darauf, dass das Element existiert, um diesen Befehl auszuführen.

Verwendung
$(selector).waitForExist({ timeout, reverse, timeoutMsg, interval })
Parameter
NameTypeDetails
options
optional
WaitForOptionswaitForEnabled Optionen (optional)
options.timeout
optional
NumberZeit in ms (Standardwert basierend auf waitforTimeout Konfigurationswert)
options.reverse
optional
Booleanwenn true, wartet es auf das Gegenteil (Standard: false)
options.timeoutMsg
optional
Stringwenn vorhanden, überschreibt es die Standard-Fehlermeldung
options.interval
optional
NumberIntervall zwischen Prüfungen (Standard: waitforInterval)
Beispiel
waitForExistSyncExample.js
it('should display a notification message after successful form submit', async () => {
const form = await $('form');
const notification = await $('.notification');
await form.$(".send").click();
await notification.waitForExist({ timeout: 5000 });
expect(await notification.getText()).to.be.equal('Data transmitted successfully!')
});
it('should remove a message after successful form submit', async () => {
const form = await $('form');
const message = await $('.message');
await form.$(".send").click();
await message.waitForExist({ reverse: true });
});
Gibt zurück
  • <Boolean> return: true wenn Element existiert (oder nicht, wenn Flag gesetzt ist)

Welcome! How can I help?

WebdriverIO AI Copilot