getText

Returns the text property of the object specified by the locator. If the object does not exist, it throws an error.

Usage in test

To use it in the test, the getText.<child_method>('<locator>',propeties<object>) method is used.

default child_method: xpath

Child Methods:
className         : Locates elements whose class name contains the search value (compound class names are not permitted)
css               : Locates elements matching a CSS selector
id                : Locates elements whose ID attribute matches the search value
name              : Locates elements whose NAME attribute matches the search value
text              : Locates anchor elements whose visible text matches the search value
partialText       : Locates anchor elements whose visible text contains the search value. If multiple elements are matching, only the first one will be selected.
linkText          : If the element we want to locate is a link, we can use the link text locator to identify it on the web page. Locates anchor elements whose visible text matches the search value
partialLinkText   : If the element we want to locate is a link, we can use the link text locator to identify it on the web page. Locates anchor elements whose visible text contains the search value. If multiple elements are matching, only the first one will be selected.
tagName           : Locates elements whose tag name matches the search value
xpath             : Locates elements matching an XPath expression
Properties:
timeout: <seconds> // defaults: 30 seconds
tests/sample1.js
/* LIBRARIES
*************/
const { sente } = require('#libraries');
const { getText } = sente;


/* TEST FLOW
*************/
test = async () => {
   
   // with xpath
   let username = await getText('//div[@id="username"]'); 
   log(username);
   
   // with xpath
   let username = await getText.xpath('//*[text()="SENTE IO"]'); 
   log(username);
   
   // with id
   let username = await getText.id('username');
   log(username); 
   
   // With timeout Properties: 
   // If it cannot find the object within 10 seconds, it throws an error.
   let username = await getText.id('username', {timeout: 10});
   log(username); 

        
}

Last updated