Questions tagged [document.evaluate]

The document.evaluate() method enables XPath queries to be performed in JavaScript in Web applications and documents. It returns an XPathResult object, with methods that enable iterating through the set of nodes that match the document.evaluate() XPath query.

The MDN Introduction to using XPath in JavaScript article provides a very good overview of how to use document.evaluate() and how to work with XPathResult objects.

document.evaluate() and XPathResult are part of the DOM3 XPath standard.

49 questions
431
votes
11 answers

Is there a way to get element by XPath using JavaScript in Selenium WebDriver?

I am looking for something like: getElementByXpath(//html[1]/body[1]/div[1]).innerHTML I need to get the innerHTML of elements using JS (to use that in Selenium WebDriver/Java, since WebDriver can't find it itself), but how? I could use ID…
pMan
  • 8,808
  • 11
  • 32
  • 35
14
votes
3 answers

document.evaluate - Cross browser?

I have been looking for a CSS selector function other than Sizzle and I have come across this function. function SparkEn(xpath,root) { xpath = xpath .replace(/((^|\|)\s*)([^/|\s]+)/g,'$2.//$3') .replace(/\.([\w-]+)(?!([^\]]*]))/g,…
Olical
  • 39,703
  • 12
  • 54
  • 77
11
votes
2 answers

xpath with dom document

I'm trying the find a xml node with xpath query. but i cannot make it working. In firefox result is always "undefined" and chrome throws a error code.