hubcap computed

Get a single computed CSS property value for an element.

When to use

Use computed to read one resolved CSS property value from the first element matching a selector. Use styles to get all computed styles at once instead of querying properties individually.

Usage

hubcap computed <selector> <property>

Arguments

ArgumentTypeRequiredDescription
selectorstringYesCSS selector for the target element
propertystringYesCSS property name to read (e.g. color, display, font-size)

Flags

None.

Output

FieldTypeDescription
propertystringThe CSS property that was queried
valuestringComputed value of the property
{"property":"color","value":"rgb(255, 0, 0)"}

Errors

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

Examples

Get the font size of a heading:

hubcap computed 'h1' 'font-size'

Check the display property:

hubcap computed '#sidebar' 'display'

Read the background color:

hubcap computed '.alert' 'background-color'

Verify an element is hidden by checking its display value:

hubcap click '#toggle' && hubcap computed '#panel' 'display'

See also

  • styles - Get all computed CSS styles at once
  • attr - Get an HTML attribute value
  • visible - Check whether an element is visible
  • bounds - Get position and dimensions of an element