Skip to main content
Version: 8.0.2

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.

Basic Usage

await I.expect(myclassName).toEqual(`className`);;

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.

Basic Usage

const element = Selector(`[class="sectionDivStyle"]`);
await I.expect(element.hasAttribute('class')).toBeTrue();

getAttribute

Gets the attribute value.

ParameterTypeDescription
attributeNamestringAttribute name.

Return value

Promise<string>

Returns the actual value of the specified attribute.

Basic Usage

const element = Selector(`[class="sectionDivStyle"]`);
await I.expect(element.getAttribute('class')).toEqual(`sectionDivStyle`);

getStyleProperty

ParameterTypeDescription
propertyNamestringProperty name.

Return value

Promise<string>

Returns the actual value of the specified style property.

Basic Usage

 await I.expect(mySelector.getStyleProperty('color')).toEqual(`rgb(0, 0, 0)`);```

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.

Basic Usage

const element = await Selector(`anySelector`).boundingClientRect;
await I.expect(element.width).toBeAtLeast(1000);

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.

Basic Usage

await I.expect(mySelector.nth(1).innerText).toEqual('TestText');

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.

Basic Usage

await I.expectSelector(mySelector.withText('TestText')).toBeVisible();

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.

Basic Usage

await I.expectSelector(mySelector.withExactText(`TestText`)).toBeVisible();

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.

Basic Usage

await I.expect(mySelector.withAttribute(`class`,`sectionDivStyle`).innerText).toEqual(`TestText`);

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.

Basic Usage

let element = Selector(`input`).filter(`[id="7cb3eb52"]`);
await I.expect(element.getAttribute('data-test-id')).toEqual(`TestText`);

filterVisible

Allows to look for a visible element matching a selector.

Return value

Selector

Returns the selector of the element.

Basic Usage

const element = Selector(`[id="7cb3eb52"]`)
await I.expect(element.filterVisible().count).toEqual(1);

filterHidden

Allows to look for an hidden element matching a selector.

Return value

Selector

Returns the selector of the element.

Basic Usage

const element = Selector(`[id="7cb3eb52"]`)
await I.expect(element.filterHidden().count).toEqual(1);

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.

Basic Usage

 let element = Selector(`[class="sectionDivStyle"]`).find(`a[href="#"]`);
await I.expect(element.innerText).toEqual(`TestText`);

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.

Basic Usage

 let element = Selector(`[data-test-id="TestTextInput"]`).parent();
await I.expect(element.getAttribute('data-control-mode')).toEqual(`input`);

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.

Basic Usage

let element = Selector(`span[class="autocomplete_span"]`).child();
await I.expect(element.getAttribute('class')).toEqual(`autocomplete_icon`);

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.

Basic Usage

const element = tableRowsElements.sibling(`//*[@id="a2"]`);
await I.expect(await element.innerText).toContain(`Name`);

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.

Basic Usage

 const tableRowsElements = Selector(`#a1`);
const element = tableRowsElements.nextSibling(2);
await I.expect(await element.innerText).toContain(`selected`);

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.

Basic Usage

 let element = Selector(`[data-test-id="201712290453170848504"]`).prevSibling();
await I.expect(element.id).toEqual(`3f3db394`);

all

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

Return value

Selector[]

Returns an array of `Selector.

Basic Usage

 for (const li of await Selector(`[class="toggle"]`).all())
await I.expect(li.className).toEqual("toggle");

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.

Basic Usage

const element = Selector(`[class="toggle"]`).with({timeout:20000});
await I.expect(element.hasAttribute('class')).toBeTrue();