跳到主要内容

等待元素可点击

等待指定毫秒数,直到元素变为可点击或不可点击状态。

信息

与其他元素命令不同,WebdriverIO 在执行此命令时不会等待元素存在。

用法
$(selector).waitForClickable({ timeout, reverse, timeoutMsg, interval })
参数
名称类型详情
options
可选
WaitForOptionswaitForEnabled 选项(可选)
options.timeout
可选
Number超时时间(毫秒)(默认基于 waitforTimeout 配置值设置)
options.reverse
可选
Boolean如果为 true,则等待相反的结果(默认值:false)
options.timeoutMsg
可选
String如果存在,将覆盖默认错误消息
options.interval
可选
Number检查间隔时间(默认值:waitforInterval
示例
waitForClickable.js
it('should detect when element is clickable', async () => {
const elem = await $('#elem')
await elem.waitForClickable({ timeout: 3000 });
});
it('should detect when element is no longer clickable', async () => {
const elem = await $('#elem')
await elem.waitForClickable({ reverse: true });
});
返回值
  • <Boolean> return: 如果元素可点击(或者当设置标志时不可点击)则返回 true

Welcome! How can I help?

WebdriverIO AI Copilot