跳至主要內容

waitForEnabled

等待以 CSS 選擇器選取的元素在指定的毫秒數內變成啟用或停用。如果透過給定的選擇器查詢多個元素,只要至少有一個元素啟用或停用,就會回傳 true。

資訊

與其他元素命令不同,WebdriverIO 不會等待元素存在才執行此命令。

用法
$(selector).waitForEnabled({ timeout, reverse, timeoutMsg, interval })
參數
名稱類型詳細資訊
options
選填
WaitForOptionswaitForEnabled 選項(選填)
options.timeout
選填
數字時間,單位為毫秒(預設值根據waitforTimeout配置值設定)
options.reverse
選填
布林值如果為 true,則等待相反的狀態(預設值:false)
options.timeoutMsg
選填
字串如果存在,則覆寫預設錯誤訊息
options.interval
選填
數字檢查之間的間隔時間(預設值:waitforInterval
範例
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 })
});

歡迎!我能幫你什麼嗎?

WebdriverIO AI Copilot