hubcap query — Query a DOM element

When to use

Query a DOM element to get its tag name and attributes. Use text or html to get content. Use exists for a boolean check.

Usage

hubcap query <selector>

Arguments

ArgumentTypeRequiredDescription
selectorstringyesCSS selector of the element to query

Flags

None.

Output

FieldTypeDescription
nodeIdnumberThe DOM node ID
tagNamestringThe element’s tag name in uppercase
attributesobjectKey-value pairs of the element’s attributes
{"nodeId":123,"tagName":"DIV","attributes":{"class":"container","id":"main"}}

Errors

ConditionExit codeStderr
Element not found0None (returns {"nodeId":0})
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

Query an element to inspect its attributes:

hubcap query '#main'

Query an element and extract its class attribute:

hubcap query '.hero' | jq -r '.attributes.class'

See also

  • text - Get inner text of an element
  • html - Get outer HTML of an element
  • attr - Get a specific attribute of an element
  • exists - Check if an element exists
  • count - Count matching elements