跳到主要内容

waitForStable

等待元素在提供的毫秒数内稳定(不再有动画)。如果选择器匹配至少一个在DOM中稳定的元素,则返回true,否则抛出错误。如果reverse标志为true,则当选择器不匹配任何稳定元素时,命令将返回true。

注意: 最好禁用动画而不是使用此命令

用法
$(selector).waitForStable({ timeout, reverse, timeoutMsg, interval })
参数
名称类型详情
options
可选
WaitForOptionswaitForStable选项(可选)
options.timeout
可选
Number时间(毫秒)(默认基于waitforTimeout配置值设置)
options.reverse
可选
Boolean如果为true,则等待相反的情况(默认值:false)
options.timeoutMsg
可选
String如果存在,它将覆盖默认错误消息
options.interval
可选
Number检查之间的间隔(默认值:waitforInterval
示例
index.html
<head>
<style>
div {
width: 200px;
height: 200px;
background-color: red;
}
#has-animation {
animation: 3s 0s alternate slidein;
}
@keyframes slidein {
from {
margin-left: 100%;
width: 300%;
}

to {
margin-left: 0%;
width: 100%;
}
}
</style>
</head>
<body>
<div #has-animation></div>
<div #has-no-animation></div>
</body>

waitForStable.js
it('should detect that element is instable and will wait for the element to become stable', async () => {
const elem = await $('#has-animation')
await elem.waitForStable({ timeout: 3000 });
});
it('should detect that element is stable and will not wait', async () => {
const elem = await $('#has-no-animation')
await elem.waitForStable();
});
返回值
  • <Boolean> return: 如果元素稳定则返回true

Welcome! How can I help?

WebdriverIO AI Copilot