getText

Get the text content from a DOM-element found by given selector. Make sure the element you want to request the text from is interactable otherwise you will get an empty string as return value. If the element is disabled or not visible and you still want to receive the text content use getHTML as a workaround.

Usage

1
client.getText(selector).then(callback);

Parameters

Param Type Details
selector String element with requested text

Example

index.html
1
2
3
4
5
6
<div id="elem">
Lorem ipsum <strong>dolor</strong> sit amet,<br>
consetetur sadipscing elitr
</div>
&nbsp;
<span style="display: none">I am invisible</span>
getText.js
1
2
3
4
5
6
7
8
9
client.getText('#elem').then(function(text) {
console.log(text);
// outputs the following:
// "Lorem ipsum dolor sit amet,consetetur sadipscing elitr"
})
.getText('span').then(function(text) {
console.log(text);
// outputs "" (empty string) since element is not interactable
});

Uses