hubcap shadow

Query an element inside a shadow DOM.

When to use

Use shadow to locate an element inside a shadow root by providing the host element selector and then the inner selector. This is required for web components that encapsulate their DOM. Use query for elements in the regular (light) DOM.

Usage

hubcap shadow <host-selector> <inner-selector>

Arguments

ArgumentTypeRequiredDescription
host-selectorstringYesCSS selector for the shadow DOM host element
inner-selectorstringYesCSS selector to match inside the shadow root

Flags

None.

Output

FieldTypeDescription
hostSelectorstringThe host element selector that was used
innerSelectorstringThe inner selector that was matched
nodeIdnumberInternal node identifier
tagNamestringElement tag name in uppercase
attributesobjectKey-value map of the element’s HTML attributes
{"hostSelector":"my-component","innerSelector":"button.inner","nodeId":123,"tagName":"BUTTON","attributes":{"class":"inner"}}

Errors

ConditionExit codeStderr
Host element not found1error: shadow host not found: <sel>
No shadow root on host1error: no shadow root found on element: <sel>
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

Query a button inside a custom element’s shadow root:

hubcap shadow 'my-component' 'button.inner'

Get an input inside a shadow host identified by ID:

hubcap shadow '#player' 'input[type=range]'

Query a shadow DOM element then extract its tag name:

hubcap shadow 'my-component' '.label' | jq -r '.tagName'

See also

  • query - Query elements in the regular DOM
  • html - Get outer HTML of an element
  • text - Get the inner text of an element