hubcap exists — Check if an element exists in the DOM

When to use

Check if an element exists in the DOM. Never errors on missing elements — returns false instead. Use visible to also check CSS visibility.

Usage

hubcap exists <selector>

Arguments

ArgumentTypeRequiredDescription
selectorstringyesCSS selector of the element to check

Flags

None.

Output

FieldTypeDescription
existsbooleanWhether the element exists in the DOM
selectorstringThe selector that was used
{"exists":true,"selector":"#login-form"}

When the element is not found:

{"exists":false,"selector":"#login-form"}

Errors

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

Examples

Check if a login form exists:

hubcap exists '#login-form'

Conditionally click a dismiss button if it exists:

hubcap exists '.cookie-banner' | jq -r '.exists' | grep -q true && hubcap click '.cookie-banner .dismiss'

See also

  • visible - Check if an element is visible
  • count - Count matching elements
  • wait - Wait for an element to appear
  • query - Query a DOM element