hubcap focus — Focus an element

When to use

Focus an element before typing. Required before type for non-input elements. Use fill to focus, clear, and type in one step.

Usage

hubcap focus <selector>

Arguments

ArgumentTypeRequiredDescription
selectorstringyesCSS selector of the element to focus

Flags

None.

Output

FieldTypeDescription
focusedbooleanWhether the focus succeeded
selectorstringThe selector that was used
{"focused":true,"selector":"#username"}

Errors

ConditionExit codeStderr
Element not found1error: element not found: <sel>
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

Focus an input field:

hubcap focus '#username'

Focus a contenteditable div, then type into it:

hubcap focus '[contenteditable]' && hubcap type 'Hello, world!'

See also

  • fill - Focus, clear, and type in one step
  • type - Type text into the focused element
  • click - Single-click an element
  • clear - Clear an input field