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
})