Przejdź do głównej treści

isFocused

Zwraca wartość prawda lub fałsz, jeśli wybrany element DOM jest obecnie aktywny (ma fokus). Jeśli selektor pasuje do wielu elementów, zwróci prawdę, jeśli jeden z elementów ma fokus.

Użycie
$(selector).isFocused()
Przykłady
index.html
<input name="login" autofocus="" />
hasFocus.js
it('should detect the focus of an element', async () => {
await browser.url('/');
const loginInput = await $('[name="login"]');
console.log(await loginInput.isFocused()); // outputs: false

await loginInput.click();
console.log(await loginInput.isFocused()); // outputs: true
})
Zwraca
  • <Boolean> return: true jeśli jeden z pasujących elementów ma fokus

Welcome! How can I help?

WebdriverIO AI Copilot