Skip to content

Instantly share code, notes, and snippets.

@clochix
Created October 12, 2012 12:17
Show Gist options
  • Select an option

  • Save clochix/3878938 to your computer and use it in GitHub Desktop.

Select an option

Save clochix/3878938 to your computer and use it in GitHub Desktop.
Sample XPath to get node by it's content
// Get a node whose content starts with (optional spaces) "Doing"
// Available functions : https://developer.mozilla.org/en-US/docs/XPath/Functions
// (regex with matches are not available, XPath 2.0, only normalized still 2007 :S )
evaluation = document.evaluate("//*[starts-with(normalize-space(.), 'Doing')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
evaluation = document.evaluate("//h2[contains(., 'part')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment