How to get text from element?

Hi All,

I want to get text from the element which is like this:

Current code:

export async function getElementWithXPath(xPathforAndroidElem: string, xPathforIOSElem: string) {
let button = {};
if (platformName === ‘android’) {
button = await driver.findElement(‘xpath’, xPathforAndroidElem);
} else if (platformName === ‘ios’) {
button = await driver.findElement(‘xpath’, xPathforIOSElem);
} else {
throw new Error(exceptionConstants[‘invalidPlatform’]);
return button;

const button1 = await getElementWithXPath(//*[contains(@content-desc,'Fastest delivery')], //*[contains(@name, 'Fastest delivery')]);
const text = await driver.getElementText(button1[‘ELEMENT’]); Text is ${text});


Here text is coming as blank.
Can someone tell me please what I am missing here?

Can you see that the Attribute ‘text’ of the element you have highlighted has a blank Value?

Try ‘content-desc’, which seems to have the Value that you want.

How can get ‘content-desc’ value? Can you please tell me because I don’t know about it.

Check Selecting element by content-desc value with Python

Have you ever done a web search? They are really handy for this type of thing:

Of those this one looks like a good bet: