Elements

session.findElement(strategy, selector)

Search for an element on the page, starting from the document root.

PARAMETERS

  • strategy: LocatorStrategy - Strategy for emelent lookup

  • selector: string - Selector string

RETURNS

Promise<Element>

EXAMPLES

const element = await session.findElement('css selector', 'h2');
// element = <webdriver element>

SEE ALSO

session.findElements(strategy, selector)

Search for multiple elements on the page, starting from the document root. The located elements will be returned as a WebElement JSON objects. The table below lists the locator strategies that each server should support. Elements should be returned in the order located in the DOM.

PARAMETERS

  • strategy: LocatorStrategy - Strategy for emelent lookup

  • selector: string - Selector string

RETURNS

Promise<Element[]>

EXAMPLES

const elements = await session.findElements('css selector', 'h2');
// elements = [<webdriver element>]

SEE ALSO

session.getActiveElement()

Get the element on the page that currently has focus.

RETURNS

Promise<Element>

EXAMPLES

const element = await session.getActiveElement();
// element = <webdriver element>

SEE ALSO

Element

This object represents a WebDriver element.

SEE ALSO

element.findElement(strategy, selector)

Search for an element on the page, starting from the referenced web element.

PARAMETERS

  • strategy: LocatorStrategy - Strategy for element lookup

  • selector: string - Selector string

RETURNS

Promise<Element>

EXAMPLES

const parent = await session.findElement('css selector', '#parent');
const child = await child.findElement('css selector', '#child');
// child = <webdriver element>

SEE ALSO

element.findElements(strategy, selector)

Search for multiple elements on the page, starting from the referenced web element. The located elements will be returned as a WebElement JSON objects. The table below lists the locator strategies that each server should support. Elements should be returned in the order located in the DOM.

PARAMETERS

  • strategy: LocatorStrategy - Strategy for emelent lookup

  • selector: string - Selector string

RETURNS

Promise<Element[]>

EXAMPLES

const parent = await session.findElement('css selector', '#parent');
const children = await child.findElements('css selector', '#child');
// elements = [<webdriver element>]

SEE ALSO

element.isSelected()

Determines if the referenced element is selected or not. This operation only makes sense on input elements of the Checkbox- and Radio Button states, or on option elements.

RETURNS

Promise<boolean>

EXAMPLES

const checkbox = await session.findElement('css selector', '#checkbox');
const selected = await checkbox.isSelected();
// selected = true

SEE ALSO

element.getAttribute(attributeName)

Returns the attribute value of the referenced web element.

PARAMETERS

  • attributeName: string - Element attribute name

RETURNS

Promise<string>

EXAMPLES

const button = await session.findElement('css selector', '#red-button');
const backgroundColor = await button.getAttribute('css');

SEE ALSO

element.getProperty(propertyName)

Returns the property of the referenced web element.

PARAMETERS

  • propertyName: string - Element property name

RETURNS

Promise<string>

EXAMPLES

const button = await session.findElement('css selector', '#red-button');
const backgroundColor = await button.getProperty('class');

SEE ALSO

element.getCssValue(propertyName)

Returns the computed value of the given CSS property for the element.

PARAMETERS

  • propertyName: string - Name of CSS property

RETURNS

Promise<string>

EXAMPLES

const button = await session.findElement('css selector', '#red-button');
const backgroundColor = await button.getCssValue('background-color');
// backgroundColor = 'rgba(255, 0, 0, 1)'

SEE ALSO

element.getText()

Returns the visible text for the element.

RETURNS

Promise<string>

EXAMPLES

const result = await session.findElement('css selector', '#result');
const text = await result.getText();

SEE ALSO

element.getTagName()

Returns the tagName of a Element

RETURNS

Promise<string>

EXAMPLES

const button = await session.findElement('css selector', '#red-button');
const backgroundColor = await button.getTagName();

SEE ALSO

element.getRect()

Returns the dimensions and coordinates of the referenced element

RETURNS

Promise<ElementRect>

EXAMPLES

const button = await session.findElement('css selector', '#red-button');
const rect = await button.getRect();
// rect = { x: 10, y: 100, width: 300, height: 50 }

SEE ALSO

element.isEnabled()

Determines if the referenced element is enabled or not.

RETURNS

Promise<boolean>

EXAMPLES

const inputField = await session.findElement('css selector', '#disabled');
const isElementEnabled = await inputField.isEnabled();

SEE ALSO

element.click()

Click on an element.

RETURNS

Promise<void>

EXAMPLES

const submitButton = await session.findElement('css selector', 'button[type="submit"]');
await submitButton.click();

SEE ALSO

element.clear()

Clear content of an element.

RETURNS

Promise<void>

EXAMPLES

const fieldA = await session.findElement('css selector', '#a');
await submitButton.clear();

SEE ALSO

element.sendKeys(text)

Send a sequence of key strokes to an element.

PARAMETERS

  • text: string - Input text to be typed in element

RETURNS

Promise<void>

EXAMPLES

const input = await session.findElement('css selector', '[name="first-name"]');
await input.sendKeys('Hello World');

SEE ALSO

LocatorStrategy

Strategy for searching element on the page

POSSIBLE VALUES

  • 'css selector'

  • 'link text'

  • 'partial link text'

  • 'tag name'

  • 'xpath'

ElementRect

An object defining the Element Rect.

PROPERTIES

  • x: number - X axis position of the top-left corner of the element relative to the current browsing context’s document element in CSS pixels

  • y: number - Y axis position of the top-left corner of the element relative to the current browsing context’s document element in CSS pixels

  • width: number - Height of the element’s bounding rectangle in CSS pixels

  • height: number - Width of the web element’s bounding rectangle in CSS pixels

Last updated