hasFocus

Return true or false if the selected DOM-element currently has focus.

Usage

1
browser.hasFocus(selector);

Parameters

Param Type Details
selector String select active element

Example

index.html
1
<input name="login" autofocus="" />
hasFocus.js
1
2
3
4
5
6
7
8
9
it('should detect the focus of an element', function () {
browser.url('/');

var loginInput = $('[name="login"]');
console.log(loginInput.hasFocus()); // outputs: false

loginInput.click();
console.log(loginInput.hasFocus()); // outputs: true
})

Uses