等待启用
Wait for an element (selected by css selector) for the provided amount of milliseconds to be (dis/en)abled. If multiple elements get queried by given selector, it returns true if at least one element is (dis/en)abled.
信息
As opposed to other element commands WebdriverIO will not wait for the element to exist to execute this command.
Usage
$(selector).waitForEnabled({ timeout, reverse, timeoutMsg, interval })
Parameters
Name | Type | Details |
---|---|---|
options optional | WaitForOptions | waitForEnabled 选项(可选) |
options.timeout optional | Number | 以毫秒为单位的时间(默认值基于 waitforTimeout 配置值设置) |
options.reverse optional | Boolean | 如果为 true,则等待相反的结果(默认值:false) |
options.timeoutMsg optional | String | 如果存在,则覆盖默认错误消息 |
options.interval optional | Number | 检查之间的间隔(默认值:waitforInterval ) |
Examples
index.html
<input type="text" id="username" value="foobar" disabled="disabled"></input>
<script type="text/javascript">
setTimeout(() => {
document.getElementById('username').disabled = false
}, 2000);
</script>
waitForEnabledExample.js
it('should detect when element is enabled', async () => {
await $('#username').waitForEnabled({ timeout: 3000 });
});
it('should detect when element is disabled', async () => {
elem = await $('#username');
await elem.waitForEnabled({ reverse: true })
});
Returns
- <Boolean>
return
: true 如果元素已(禁用/启用)