Selector API methods
hasClass
Checks if an element has a specific class.
Parameter | Type | Description |
---|---|---|
className | string | Class 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.
Parameter | Type | Description |
---|---|---|
attributeName | string | Attribute 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.
Parameter | Type | Description |
---|---|---|
attributeName | string | Attribute 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
Parameter | Type | Description |
---|---|---|
propertyName | string | Property 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
Parameter | Type | Description |
---|---|---|
propertyName | string | Property 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.
Parameter | Type | Description |
---|---|---|
index | number | Element 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.
Parameter | Type | Description |
---|---|---|
value | string / RegExp | Text 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.
Parameter | Type | Description |
---|---|---|
value | string | Text 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.
Parameter | Type | Description |
---|---|---|
attrName | string / RegExp | Attribute name to search for. |
attrValue | string / RegExp | Attribute 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.
Parameter | Type | Description |
---|---|---|
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.
Parameter | Type | Description |
---|---|---|
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.
Parameter | Type | Description |
---|---|---|
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.
Parameter | Type | Description |
---|---|---|
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.
Parameter | Type | Description |
---|---|---|
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.
Parameter | Type | Description |
---|---|---|
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.
Parameter | Type | Description |
---|---|---|
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.
Parameter | Type | Description |
---|---|---|
cloneActions | boolean / 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.
Parameter | Type | Description |
---|---|---|
options | object | Selector options. |
options
Selector options
Parameter | Type | Description |
---|---|---|
interval | number | Time interval between retries in milliseconds. |
timeout | number | Timeout of the method. |
retries | number | Number of retries. |
backoff | FIXED / EXPONENTIAL / LINEAR | Value used to determine the wait time between successive retries. |
maxBackOff | number | Maximum value of backoff. |
errorMessage | string | Error message. |
overrideErrorMessage | string | Override the Test Maker error message. |
retryMessage | string | Retry 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();