想要在 XPath 上打印文本

Want to Print the text on the XPath

const myAdress = (`My Address = +${'//android.widget.TextView[@index="1"]'}`);
console.log(myAdress);

想要打印此特定 XPath 上的文本,但它按原样打印。

您可以在 xpath 中使用部分文本,而不是附加文本,例如

String address = "//*[contains(@text,'replace your address')]"


String printAddress= driver.findElementByXPath(address).getText();
log.info(printAddress);
const myAdress = (`My Address is ${$('//android.widget.TextView[@index="1"]').getText()}`);
console.log(myAdress);

你的括号有问题。

这样更清楚:

const element = $('//android.widget.TextView[@index="1"]') 
const text = element.getText()
console.log(`My address is ${text}`)