hubcap bounds — Get element bounding box

When to use

Get the bounding box of an element for coordinate calculations. Use with clickat to click at relative positions within or near an element.

Usage

hubcap bounds <selector>

Arguments

ArgumentTypeRequiredDescription
selectorstringyesCSS selector of the element

Flags

None.

Output

FieldTypeDescription
xnumberLeft edge x-coordinate in pixels
ynumberTop edge y-coordinate in pixels
widthnumberWidth in pixels
heightnumberHeight in pixels
{"x":100,"y":200,"width":300,"height":50}

Errors

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

Examples

Get the bounding box of a header:

hubcap bounds 'header'

Get bounds and compute the center point for a click:

hubcap bounds '.canvas' | jq '{x: (.x + .width/2), y: (.y + .height/2)}'

See also

  • clickat - Click at specific coordinates
  • mouse - Move mouse to coordinates
  • visible - Check if an element is visible
  • layout - Get element layout with children