简体   繁体   中英

Is there a way to get the Text of an element using its Xpath in JavaScript?

I need to get the text of an element by passing its Xpath in Java Script.

I am using an Automation Tool, Where it supports only JavaScript. And I need to get the Text of number of elements, where the element count changes dynamically. So, I want to get the text of the elements I want by passing the Xpath in JavaScript.

Did you try document.evaluate() ?

var h1_text = document.evaluate('//h1/text()', document, null, XPathResult.STRING_TYPE, null).stringValue;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM