hubcap count — Count elements matching a selector

When to use

Count elements matching a selector. Returns 0 if none found (does not error). Use exists for a boolean check.

Usage

hubcap count <selector>

Arguments

ArgumentTypeRequiredDescription
selectorstringyesCSS selector to count matches for

Flags

None.

Output

FieldTypeDescription
countnumberThe number of matching elements
selectorstringThe selector that was used
{"count":5,"selector":"ul.results li"}

Errors

ConditionExit codeStderr
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

Count list items:

hubcap count 'ul.results li'

Count items and use the result in a script:

hubcap count '.notification' | jq -r '.count'

See also

  • exists - Check if an element exists
  • query - Query a DOM element
  • visible - Check if an element is visible