Namespace: element

element

This module provides shared functionality for dealing with DOM- and web elements in Marionette.

A web element is an abstraction used to identify an element when it is transported across the protocol, between remote- and local ends.

Each element has an associated web element reference (a UUID) that uniquely identifies the the element across all browsing contexts. The web element reference for every element representing the same element is the same.

The element.Store provides a mapping between web element references and DOM elements for each browsing context. It also provides functionality for looking up and retrieving elements.

Source:

Classes

Store

Methods

(static) coordinates(node, xOffsetopt, yOffsetopt) → {Object.<string, number>}

This function generates a pair of coordinates relative to the viewport given a target element and coordinates relative to that element's top-left corner.

Parameters:
Name Type Attributes Description
node Node

Target node.

xOffset number <optional>

Horizontal offset relative to target's top-left corner. Defaults to the centre of the target's bounding box.

yOffset number <optional>

Vertical offset relative to target's top-left corner. Defaults to the centre of the target's bounding box.

Source:
Throws:

TypeError If |xOffset| or |yOffset| are not numbers.

Returns:

X- and Y coordinates.

Type
Object.<string, number>

(static) find(container, strategy, selector, opts) → {Promise.<(nsIDOMElement|Array.<nsIDOMElement>)>}

Find a single element or a collection of elements starting at the document root or a given node.

If |timeout| is above 0, an implicit search technique is used. This will wait for the duration of |timeout| for the element to appear in the DOM.

See the |element.Strategy| enum for a full list of supported search strategies that can be passed to |strategy|.

Available flags for |opts|:

|all|
  If true, a multi-element search selector is used and a sequence
  of elements will be returned.  Otherwise a single element.

|timeout|
  Duration to wait before timing out the search.  If |all| is
  false, a NoSuchElementError is thrown if unable to find
  the element within the timeout duration.

|startNode|
  Element to use as the root of the search.
Parameters:
Name Type Description
container Object.<string, Window>

Window object and an optional shadow root that contains the root shadow DOM element.

strategy string

Search strategy whereby to locate the element(s).

selector string

Selector search pattern. The selector must be compatible with the chosen search |strategy|.

opts Object.<string, ?>

Options.

Source:
Throws:
  • InvalidSelectorError If |strategy| is unknown.

  • InvalidSelectorError If |selector| is malformed.

  • NoSuchElementError If a single element is requested, this error will throw if the element is not found.

Returns:

Single element or a sequence of elements.

Type
Promise.<(nsIDOMElement|Array.<nsIDOMElement>)>

(static) findByLinkText(node, s) → {Array.<DOMAnchorElement>}

Find all hyperlinks dscendant of |node| which link text is |s|.

Parameters:
Name Type Description
node DOMElement

Where in the DOM hierarchy to being searching.

s string

Link text to search for.

Source:
Returns:

Sequence of link elements which text is |s|.

Type
Array.<DOMAnchorElement>

(static) findByPartialLinkText(node, s) → {Array.<DOMAnchorElement>}

Find all hyperlinks descendant of |node| which link text contains |s|.

Parameters:
Name Type Description
node DOMElement

Where in the DOM hierachy to begin searching.

s string

Link text to search for.

Source:
Returns:

Sequence of link elements which text containins |s|.

Type
Array.<DOMAnchorElement>

(static) findByXPath(root, startNode, expr) → {DOMElement}

Find a single element by XPath expression.

Parameters:
Name Type Description
root DOMElement

Document root

startNode DOMElement

Where in the DOM hiearchy to begin searching.

expr string

XPath search expression.

Source:
Returns:

First element matching expression.

Type
DOMElement

(static) findByXPathAll(root, startNode, expr) → {Array.<DOMElement>}

Find elements by XPath expression.

Parameters:
Name Type Description
root DOMElement

Document root.

startNode DOMElement

Where in the DOM hierarchy to begin searching.

expr string

XPath search expression.

Source:
Returns:

Sequence of found elements matching expression.

Type
Array.<DOMElement>

(static) getContainer(el) → {Element}

Gets the element's container element.

An element container is defined by the WebDriver specification to be an