Перейти до основного вмісту

isFocused

Повертає true або false, якщо вибраний DOM-елемент наразі має фокус. Якщо селектор відповідає декільком елементам, буде повернуто true, якщо один з елементів має фокус.

Usage
$(selector).isFocused()
Examples
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
})
Returns
  • <Boolean> return: true if one of the matching elements has focus

Welcome! How can I help?

WebdriverIO AI Copilot