メインコンテンツにスキップ

isFocused

選択されたDOM要素が現在フォーカスされているかどうかをtrueまたはfalseで返します。セレクタが複数の要素に一致する場合、それらのうちの一つにフォーカスがあれば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
})
戻り値
  • <Boolean> return: 一致する要素のいずれかにフォーカスがある場合はtrue

Welcome! How can I help?

WebdriverIO AI Copilot