waitForExist
等待元素在 DOM 中出現指定的毫秒數。如果選擇器符合 DOM 中至少一個存在的元素,則返回 true,否則拋出錯誤。如果 reverse 標誌為 true,則如果選擇器不符合任何元素,則命令將返回 true。
資訊
與其他元素命令相反,WebdriverIO 不會等待元素存在後才執行此命令。
用法
$(selector).waitForExist({ timeout, reverse, timeoutMsg, interval })
參數
名稱 | 類型 | 詳細資訊 |
---|---|---|
options 可選 | WaitForOptions | waitForEnabled 選項 (可選) |
options.timeout 可選 | 數字 | 以毫秒為單位的時間(預設根據waitforTimeout 配置值設定) |
options.reverse 可選 | 布林值 | 如果為 true,則等待相反的結果(預設值:false) |
options.timeoutMsg 可選 | 字串 | 如果存在,則覆蓋預設錯誤訊息 |
options.interval 可選 | 數字 | 檢查之間的間隔時間(預設值: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 });
});