Zum Hauptinhalt springen

waitForStable

Wartet auf ein Element für die angegebene Anzahl von Millisekunden, bis es stabil ist (sich nicht bewegt). Gibt true zurück, wenn der Selektor mindestens ein Element im DOM findet, das stabil ist, andernfalls wird ein Fehler ausgegeben. Wenn das reverse-Flag auf true gesetzt ist, gibt der Befehl stattdessen true zurück, wenn der Selektor keine stabilen Elemente findet.

Hinweis: Es ist besser, Animationen zu deaktivieren, anstatt diesen Befehl zu verwenden

Verwendung
$(selector).waitForStable({ timeout, reverse, timeoutMsg, interval })
Parameter
NameTypeDetails
options
optional
WaitForOptionswaitForStable Optionen (optional)
options.timeout
optional
NumberZeit in ms (Standardwert basiert auf dem 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 den Prüfungen (Standard: waitforInterval)
Beispiele
index.html
<head>
<style>
div {
width: 200px;
height: 200px;
background-color: red;
}
#has-animation {
animation: 3s 0s alternate slidein;
}
@keyframes slidein {
from {
margin-left: 100%;
width: 300%;
}

to {
margin-left: 0%;
width: 100%;
}
}
</style>
</head>
<body>
<div #has-animation></div>
<div #has-no-animation></div>
</body>

waitForStable.js
it('should detect that element is instable and will wait for the element to become stable', async () => {
const elem = await $('#has-animation')
await elem.waitForStable({ timeout: 3000 });
});
it('should detect that element is stable and will not wait', async () => {
const elem = await $('#has-no-animation')
await elem.waitForStable();
});
Rückgabewert
  • <Boolean> return: true wenn Element stabil ist

Welcome! How can I help?

WebdriverIO AI Copilot