Returns the shadowRoot read-only property which represents the shadow root hosted by the element. This can further be used to retrieve elements part of the shadow root element.

For more info on working with DOM elements in Nightwatch, refer to the Finding & interacting with DOM Elements guide page.

Usage

browser.getShadowRoot(selector, [callback])
browser.getShadowRoot(selector)

Example

Or run locally with:
git clone https://github.com/nightwatchjs/nightwatch-examples.git
cd nightwatch-examples
npm install
npx nightwatch tests/api/getShadowRoot.js

Parameters

Name Type description
using
Optional
string

The locator strategy to use. See W3C Webdriver - locator strategies

selector string|object|WebElement|By

The selector (CSS/Xpath) used to locate the element. Can either be a string or an object which specifies element properties.

callback function

Callback function which is called with the result value.

Recommended content