Skip to main content
Version: 7.5.5

Selector API methods

hasClass

Checks if an element has a specific class.

ParameterTypeDescription
classNamestringClass name.

Return value

Promise<boolean>

Returns true if element has the specified class name.

hasAttribute

Checks if an element has a specific attribute.

ParameterTypeDescription
attributeNamestringAttribute name.

Return value

Promise<boolean>

Returns true if element has the specified attribute name.

getAttribute

Gets the attribute value.

ParameterTypeDescription
attributeNamestringAttribute name.

Return value

Promise<string>

Returns the actual value of the specified attribute.

getStyleProperty

ParameterTypeDescription
propertyNamestringProperty name.

Return value

Promise<string>

Returns the actual value of the specified style property.

getBoundingClientRectProperty

ParameterTypeDescription
propertyNamestringProperty name.

Return value

Promise<number>

Returns the actual value of the specified property about the element size or position relative to viewport.

nth

Matches an element based on their position among a group of siblings. The group of siblings is composed of any type of element.

ParameterTypeDescription
indexnumberElement position among group of siblings.

Return value

Selector

Returns (depending on the index value) one of the selector matching the initial selector.

withText

Allows to look for an element that contains the specified text.

ParameterTypeDescription
valuestring / RegExpText value to search for.

Return value

Selector

Returns the selector of the element.

withExactText

Allows to look for an element that contains the specified exact text.

ParameterTypeDescription
valuestringText value to search for.

Return value

Selector

Returns the selector of the element.

withAttribute

Allows to look for an element that contains the specified attribute.

ParameterTypeDescription
attrNamestring / RegExpAttribute name to search for.
attrValuestring / RegExpAttribute value to search for.

Return value

Selector

Returns the selector of the element.

filter

Allows to look for an element that contains the specified selector.

ParameterTypeDescription
cssSelector / xPathSelector / filterFn,dependencies?string / string/ (node: Element, idx?: number, originNode?: Element) => boolean,{[key: string]: any;}Selector matching the element.

filter Return value

Selector

Returns the selector of the element.

filterVisible

Allows to look for a visible element matching a selector.

Return value

Selector

Returns the selector of the element.

filterHidden

Allows to look for an hidden element matching a selector.

Return value

Selector

Returns the selector of the element.

find

Allows to look for element matching a selector CSS selector.

ParameterTypeDescription
cssSelector / xPathSelector / filterFn,dependencies?string / string/ (node: Element, idx?: number, originNode?: Element) => boolean,{[key: string]: any;}Selector matching the element.

find Return value

Selector

Returns the selector of the element.

parent

Allows to look for a parent selector.

ParameterTypeDescription
index / cssSelector / xPathSelector / filterFn,dependencies?number / string / string / (node: Element, idx?: number, originNode?: Element) => boolean,{[key: string]: any;}Selector or index matching the element.

parent Return value

Selector

Returns the selector of the element.

child

Allows to look for a child selector.

ParameterTypeDescription
index / cssSelector / xPathSelector / filterFn,dependencies?number / string / string / (node: Element, idx?: number, originNode?: Element) => boolean,{[key: string]: any;}Selector or index matching the element.

child Return value

Selector

Returns the selector of the element.

sibling

Allows to look for a sibling selector.

ParameterTypeDescription
index / cssSelector / xPathSelector / filterFn,dependencies?number / string / string / (node: Element, idx?: number, originNode?: Element) => boolean,{[key: string]: any;}Selector or index matching the element.

sibling Return value

Selector

Returns the selector of the element.

nextSibling

Allows to look for a among the next sibling selector.

ParameterTypeDescription
index / cssSelector / xPathSelector / filterFn,dependencies?number / string / string / (node: Element, idx?: number, originNode?: Element) => boolean,{[key: string]: any;}Selector or index matching the element.

nextSibling Return value

Selector

Returns the selector of the element.

prevSibling

Allows to look for a among the next sibling selector.

ParameterTypeDescription
index / cssSelector / xPathSelector / filterFn,dependencies?number / string / string / function,{[key: string]: any;}Selector or index matching the element.

prevSibling Return value

Selector

Returns the selector of the element.

all

Allows to gather all occurrences of a Selector inside an array.

Return value

Selector[]

Returns an array of `Selector.

clone

Allows to clone a specific selector.

ParameterTypeDescription
cloneActionsboolean / undefined·Enable clone actions.

Return value

Selector

Returns a duplicate of the selector on which the method was called .

with

The with statement extends the scope chain for a statement.

ParameterTypeDescription
optionsobjectSelector options.

options

Selector options

ParameterTypeDescription
intervalnumberTime interval between retries in milliseconds.
timeoutnumberTimeout of the method.
retriesnumberNumber of retries.
backoffFIXED / EXPONENTIAL / LINEARValue used to determine the wait time between successive retries.
maxBackOffnumberMaximum value of backoff.
errorMessagestringError message.
overrideErrorMessagestringOverride the Test Maker error message.
retryMessagestringRetry message.

Return value

Selector

Returns the selector of the element.

expect

ParameterTypeDescription
optionsobjectAssertion options.

options

Assertion options

ParameterTypeDescription
intervalnumberTime interval between retries in milliseconds.
timeoutnumberTimeout of the method.
retriesnumberNumber of retries.
backoffFIXED / EXPONENTIAL / LINEAR / ((attempt: number, delay: number) => number)Value used to determine the wait time between successive retries .
maxBackOffnumberMaximum value of backoff.
errorMessagestringError message.
overrideErrorMessagestringOverride the Test Maker error message.
retryMessagestringRetry message.

Return value

number

Value used to determine the wait time between successive retries.

waitForToExist

Description

Waits for the Selector to exist in the DOM.

Basic usage

import { Feature, Selector } from 'test-maker';

Feature(`Example Feature`)
.Scenario(`Example Scenario`)
.Given(`We Visit google search page`, async (I) => {
// Wait for the body to exist with a custom timeout of 5 seconds and a polling interval of 300 milliseconds
await Selector("body", { timeout: 5000, interval: 300 }).waitForToExist();
});

waitForToNotExist

Description

Waits for the Selector to not exist in the DOM.

Basic usage

import { Feature, Selector } from 'test-maker';

Feature(`Example Feature`)
.Scenario(`Example Scenario`)
.Given(`We Visit google search page`, async (I) => {
// Wait for the body to not exist with a custom timeout of 5 seconds and a polling interval of 300 milliseconds
await Selector("body", { timeout: 5000, interval: 300 }).waitForToNotExist();
});

waitForToBeVisible

Description

Waits for the Selector to become visible.

Basic usage

import { Feature, Selector } from 'test-maker';

Feature(`Example Feature`)
.Scenario(`Example Scenario`)
.Given(`We Visit google search page`, async (I) => {
// Wait for the body to become visible with a custom timeout of 5 seconds and a polling interval of 300 milliseconds
await Selector("body", { timeout: 5000, interval: 300 }).waitForToBeVisible();
});

waitForToBeInvisible

Description

Waits for the Selector to become invisible.

Basic usage

import { Feature, Selector } from 'test-maker';

Feature(`Example Feature`)
.Scenario(`Example Scenario`)
.Given(`We Visit google search page`, async (I) => {
// Wait for the body to become invisible with a custom timeout of 5 seconds and a polling interval of 300 milliseconds
await Selector("body", { timeout: 5000, interval: 300 }).waitForToBeInvisible();
});

waitForActionabilityCheck

Description

Waits for various actionability checks on the Selector. Actionability checks include checks for attached, stable, visible, enabled, and editable states.

Basic usage

import { Feature, Selector } from 'test-maker';

Feature(`Example Feature`)
.Scenario(`Example Scenario`)
.Given(`We Visit google search page`, async (I) => {
// Wait for actionability checks on the body Selector with a custom timeout of 5 seconds and a polling interval of 300 milliseconds
await Selector("body", { timeout: 5000, interval: 300 }).waitForActionabilityCheck(['attached', 'visible']);
});

In this example, the Selector "body" will be checked for attachment and visibility. You can customize the actionability checks by passing different combinations of ActionabilityCheckTypes to the waitForActionabilityCheck method.