Vai al contenuto principale

waitForExist

Attende che un elemento sia presente nel DOM per il numero di millisecondi specificato. Restituisce true se il selettore corrisponde ad almeno un elemento esistente nel DOM, altrimenti genera un errore. Se il flag reverse è true, il comando restituirà true se il selettore non corrisponde a nessun elemento.

informazione

A differenza di altri comandi per elementi, WebdriverIO non attenderà che l'elemento esista per eseguire questo comando.

Utilizzo
$(selector).waitForExist({ timeout, reverse, timeoutMsg, interval })
Parametri
NomeTipoDettagli
options
opzionale
WaitForOptionsopzioni waitForEnabled (opzionale)
options.timeout
opzionale
Numbertempo in ms (valore predefinito basato sulla 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)
Esempio
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 });
});
Restituisce
  • <Boolean> return: true se l'elemento esiste (o non esiste se il flag è impostato)

Welcome! How can I help?

WebdriverIO AI Copilot