等待元素存在
等待元素在提供的毫秒数内在DOM中存在。如果选择器匹配DOM中至少一个存在的元素,则返回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