本文へスキップ

isFocused

選択されたDOM要素が現在フォーカスを持っているかどうかを真偽値で返します。セレクタが複数の要素に一致する場合、要素のいずれかがフォーカスを持っている場合はtrueを返します。

使用方法
$(selector).isFocused()
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
})

ようこそ!お手伝いできることはありますか?

WebdriverIO AI Copilot