ShadowRoot

Represents a ShadowRoot of a WebElement. Provides functions to retrieve elements that live in the DOM below the ShadowRoot.

Constructor

new ShadowRoot()

Methods

findElement(locatornon-null) → (non-null) {WebElementPromise}

Schedule a command to find a descendant of this ShadowROot. If the element cannot be found, the returned promise will be rejected with a NoSuchElementError.

The search criteria for an element may be defined using one of the static factories on the by.By class, or as a short-hand ./by.ByHash object. For example, the following two statements are equivalent:

var e1 = shadowroot.findElement(By.id('foo'));
var e2 = shadowroot.findElement({id:'foo'});

You may also provide a custom locator function, which takes as input this instance and returns a WebElement, or a promise that will resolve to a WebElement. If the returned promise resolves to an array of WebElements, WebDriver will use the first element. For example, to find the first visible link on a page, you could write:

var link = element.findElement(firstVisibleLink);

function firstVisibleLink(shadowRoot) {
  var links = shadowRoot.findElements(By.tagName('a'));
  return promise.filter(links, function(link) {
    return link.isDisplayed();
  });
}
Parameters:
NameTypeDescription
locatorby.By | function

The locator strategy to use when searching for the element.

Returns:

A WebElement that can be used to issue commands against the located element. If the element is not found, the element will be invalidated and all scheduled commands aborted.

Type: 
WebElementPromise

(async) findElements(locatornon-null) → (non-null) {Promise.<!Array.<!WebElement>>}

Locates all the descendants of this element that match the given search criteria.

Parameters:
NameTypeDescription
locatorby.By | function

The locator strategy to use when searching for the element.

Returns:

A promise that will resolve to an array of WebElements.

Type: 
Promise.<!Array.<!WebElement>>

(static) extractId(obj) → {string}

Extracts the encoded ShadowRoot ID from the object.

Parameters:
NameTypeDescription
obj?

The object to extract the ID from.

Throws:

if the object is not a valid encoded ID.

Type
TypeError
Returns:

the extracted ID.

Type: 
string

(static) isId(obj) → {boolean}

Parameters:
NameTypeDescription
obj?

the object to test.

Returns:

whether the object is a valid encoded WebElement ID.

Type: 
boolean