waitForExist
指定されたミリ秒間、要素がDOM内に存在するのを待ちます。セレクタがDOM内に存在する少なくとも1つの要素にマッチする場合はtrueを返し、それ以外の場合はエラーをスローします。reverseフラグがtrueの場合、コマンドはセレクタが要素にマッチしない場合にtrueを返します。
情報
他の要素コマンドとは異なり、WebdriverIOはこのコマンドを実行するために要素が存在するのを待ちません。
使用法
$(selector).waitForExist({ timeout, reverse, timeoutMsg, interval })
パラメータ
名前 | 型 | 詳細 |
---|---|---|
options オプション | WaitForOptions | waitForEnabledオプション(オプション) |
options.timeout オプション | Number | ミリ秒単位の時間(デフォルトはwaitforTimeout 設定値に基づく) |
options.reverse オプション | Boolean | trueの場合、反対の結果を待ちます(デフォルト:false) |
options.timeoutMsg オプション | String | 存在する場合、デフォルトのエラーメッセージを上書きします |
options.interval オプション | Number | チェック間の間隔(デフォルト:waitforInterval ) |
例
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 });
});
戻り値
- <Boolean>
return
: 要素が存在する場合(またはフラグが設定されている場合は存在しない場合)true