View Source Improve this doc

hasFocus

Return true or false if the selected DOM-element currently has focus. If the selector matches multiple elements, it will return true if one of the elements has focus.

Usage

1
browser.hasFocus(selector);

Parameters

Param Type Details
selector String selector for element(s) to test for focus

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

Returns

  • <Boolean>: true if one of the matching elements has focus

Uses