.getText(options)
Retrieves text content of element.
Usage
element(matcher).getText(options)
Parameters
options
(Object?
):options.recursive
(Boolean?
): Determines whether to recursively retrieve the inner text. Often useful on Android when text is fragmented, but can be used to retrieve text from grouping elements such as list items. Defaults to false.
Returns
Promise
(String
): Element text contents.
Support
Platform | Supported |
---|---|
iOS | Yes |
Android | Yes |
Web | Yes |
Examples
Text element:
const { element, by, expect } = require("appdriver");
(async () => {
const text = await element(by.label("text"))
.getText();
await expect(text).toEqual("Hello World!");
})();
Button (nested text):
const { element, by, expect } = require("appdriver");
(async () => {
const text = await element(by.label("button"))
.getText({ recursive: true });
await expect(text).toEqual("Press Me!");
})();
Text Input:
const { element, by, expect } = require("appdriver");
(async () => {
const text = await element(by.label("text-input"))
.getText();
await expect(text).toEqual("Hello World!");
})();