0

i am getting the the element on the web page by the xpath using the evaluate function.

var ele = document.evaluate(request.path, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var node = ele.snapshotItem(0);
alert(node.textContent);

But this gives undefined, may anyone help me with this ?

Abhishek Tripathi
  • 1,211
  • 2
  • 15
  • 30
  • What are you specifically trying to target within your document? Any example of your existing HTML would be helpful as jQuery and Javascript can easily handle this sort of thing. What does your `ele` value look like that is being returned from your `document.evaluate()` call? – Rion Williams Apr 27 '16 at 17:27
  • http://stackoverflow.com/questions/14631590/get-text-content-of-an-html-element-using-xpath – 8protons Apr 27 '16 at 17:30
  • 1
    What's the result of `node.nodeType`? – zzzzBov Apr 27 '16 at 17:34
  • targets will be the texts on the web pages ! and ele is the element object as the evaluate functions returns the web element to which the input xpath points to. – Abhishek Tripathi Apr 27 '16 at 17:34
  • That shouldn't be possible. `snapshotItem` should return a DOM node or null. Accessing `textContent` on the former should throw, on the latter it should return a string (maybe empty string but not undefined). – Oriol Apr 27 '16 at 17:37
  • One question i want to ask once i get the element by evaluate then it need s the webpage to show text ? – Abhishek Tripathi Apr 27 '16 at 17:48

0 Answers0