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
Nome | Tipo | Dettagli |
---|---|---|
options opzionale | WaitForOptions | opzioni waitForEnabled (opzionale) |
options.timeout opzionale | Number | tempo in ms (valore predefinito basato sulla configurazione waitforTimeout ) |
options.reverse opzionale | Boolean | se true attende l'opposto (predefinito: false) |
options.timeoutMsg opzionale | String | se esiste, sovrascrive il messaggio di errore predefinito |
options.interval opzionale | Number | intervallo 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)