Pular para o conteúdo principal

isFocused

Retorna verdadeiro ou falso se o elemento DOM selecionado atualmente tem foco. Se o seletor corresponder a múltiplos elementos, retornará verdadeiro se um dos elementos tiver foco.

Uso
$(selector).isFocused()
Exemplos
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
})
Retorna
  • <Boolean> return: verdadeiro se um dos elementos correspondentes tiver foco

Welcome! How can I help?

WebdriverIO AI Copilot