Hoppa till huvudinnehåll

waitForEnabled

Vänta på att ett element (valt med css-väljare) ska vara (in/ak)tiverat under den angivna tiden i millisekunder. Om flera element väljs med den angivna väljaren, returneras true om minst ett element är (in/ak)tiverat.

info

Till skillnad från andra elementkommandon kommer WebdriverIO inte att vänta på att elementet ska existera för att utföra detta kommando.

Användning
$(selector).waitForEnabled({ timeout, reverse, timeoutMsg, interval })
Parametrar
NameTypeDetails
options
optional
WaitForOptionswaitForEnabled options (optional)
options.timeout
optional
Numbertime in ms (default set based on waitforTimeout config value)
options.reverse
optional
Booleanif true it waits for the opposite (default: false)
options.timeoutMsg
optional
Stringif exists it overrides the default error message
options.interval
optional
Numberinterval between checks (default: waitforInterval)
Exempel
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 })
});
Returnerar
  • <Boolean> return: true if element is (dis/en)abled

Welcome! How can I help?

WebdriverIO AI Copilot