Vai al contenuto principale

waitForStable

Attendi che un elemento sia stabile (non in animazione) per il numero di millisecondi fornito. Restituisce true se il selettore corrisponde ad almeno un elemento stabile nel DOM, altrimenti genera un errore. Se il flag reverse è true, il comando restituirà invece true se il selettore non corrisponde a nessun elemento stabile.

Nota: è meglio disabilitare le animazioni invece di utilizzare questo comando

Utilizzo
$(selector).waitForStable({ timeout, reverse, timeoutMsg, interval })
Parametri
NomeTipoDettagli
options
opzionale
WaitForOptionsopzioni waitForStable (opzionale)
options.timeout
opzionale
Numbertempo in ms (predefinito basato sul valore di configurazione waitforTimeout)
options.reverse
opzionale
Booleanse true attende l'opposto (predefinito: false)
options.timeoutMsg
opzionale
Stringse esiste sovrascrive il messaggio di errore predefinito
options.interval
opzionale
Numberintervallo tra i controlli (predefinito: waitforInterval)
Esempi
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();
});
Restituisce
  • <Boolean> return: true se l'elemento è stabile

Welcome! How can I help?

WebdriverIO AI Copilot