Skip to content

Instantly share code, notes, and snippets.

@Enissay
Forked from LeCoupa/xpath-cheatsheet.js
Last active February 15, 2016 18:43

Revisions

  1. Enissay revised this gist Feb 15, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@


    '//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
    '//hr[contains(@class, 'class1')]' // every hr having that classs among others (the above wont work if multi-class)
    '//table[count(tr)=1 and count(tr/td)=2]' // all tables with 1 row and 2 cols
    '//div/form/parent::*' // all divs that have form
    './div/b' // a relative path
  2. Julien Le Coupanec revised this gist Aug 13, 2014. No changes.
  3. Julien Le Coupanec revised this gist Jul 25, 2014. No changes.
  4. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -198,3 +198,18 @@ substring-after(haystack, needle) // returns a string that is the rest o
    substring-before(haystack, needle) // returns a string that is the rest of a given string before a given substring.
    translate(string, abc, XYZ) // evaluates a string and a set of characters to translate and returns the translated string.


    // 12. XPath Axes.

    ancestor // indicates all the ancestors of the context node beginning with the parent node and traveling through to the root node.
    ancestor-or-self // indicates the context node and all of its ancestors, including the root node.
    attribute (@) // indicates the attributes of the context node. Only elements have attributes. This axis can be abbreviated with the at sign (@).
    child (/) // indicates the children of the context node. If an XPath expression does not specify an axis, this is understood by default. Since only the root node or element nodes have children, any other use will select nothing.
    descendant (//) // indicates all of the children of the context node, and all of their children, and so forth. Attribute and namespace nodes are not included - the parent of an attribute node is an element node, but attribute nodes are not the children of their parents.
    descendant-or-self // indicates the context node and all of its descendants. Attribute and namespace nodes are not included - the parent of an attribute node is an element node, but attribute nodes are not the children of their parents.
    following // indicates all the nodes that appear after the context node, except any descendant, attribute, and namespace nodes.
    following-sibling // indicates all the nodes that have the same parent as the context node and appear after the context node in the source document.
    parent(..) // indicates the single node that is the parent of the context node. It can be abbreviated as two periods (..).
    preceding // indicates all the nodes that precede the context node in the document except any ancestor, attribute and namespace nodes.
    preceding-sibling // indicates all the nodes that have the same parent as the context node and appear before the context node in the source document.
    self (.) // indicates the context node itself. It can be abbreviated as a single period (.).
  5. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -188,13 +188,13 @@ position() // returns a number equal to the context position from
    // 11.6. String.


    contains(haystack-string, needle-string) //
    concat(string1, string2 [stringn]*) //
    normalize-space(string) //
    starts-with(haystack ,needle) //
    string-length([string]) //
    substring(string, start [length]) //
    substring-after(haystack, needle) //
    substring-before(haystack, needle) //
    translate( string, abc, XYZ) //
    contains(haystack-string, needle-string) // determines whether the first argument string contains the second argument string and returns boolean true or false.
    concat(string1, string2 [stringn]*) // concatenates two or more strings and returns the resulting string.
    normalize-space(string) // strips leading and trailing white-space from a string, replaces sequences of whitespace characters by a single space, and returns the resulting string.
    starts-with(haystack, needle) // checks whether the first string starts with the second string and returns true or false.
    string-length([string]) // returns a number equal to the number of characters in a given string.
    substring(string, start [length]) // returns a part of a given string.
    substring-after(haystack, needle) // returns a string that is the rest of a given string after a given substring.
    substring-before(haystack, needle) // returns a string that is the rest of a given string before a given substring.
    translate(string, abc, XYZ) // evaluates a string and a set of characters to translate and returns the translated string.

  6. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -179,10 +179,10 @@ namespace-uri([node-set]) // returns a string representing the namespace URI of
    // 11.5. Context.


    count(node-set) //
    function-available(name) //
    last() //
    position() //
    count(node-set) // counts the number of nodes in a node-set and returns an integer.
    function-available(name) // determines if a given function is available and returns boolean true or false.
    last() // returns a number equal to the context size from the expression evaluation context.
    position() // returns a number equal to the context position from the expression evaluation context.


    // 11.6. String.
  7. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -171,7 +171,7 @@ not(expression) // evaluates a boolean expression and returns the opposite valu
    // 11.4. Node.


    lang(string) // determines whether the context node matches the given language and returns boolean true or false.
    lang(string) // determines whether the context node matches the given language and returns boolean true or false.
    name([node-set]) // returns a string representing the QName of the first node in a given node-set.
    namespace-uri([node-set]) // returns a string representing the namespace URI of the first node in a given node-set.

  8. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -172,7 +172,7 @@ not(expression) // evaluates a boolean expression and returns the opposite valu


    lang(string) // determines whether the context node matches the given language and returns boolean true or false.
    name([node-set]) // returns a string representing the QName of the first node in a given node-set.
    name([node-set]) // returns a string representing the QName of the first node in a given node-set.
    namespace-uri([node-set]) // returns a string representing the namespace URI of the first node in a given node-set.


  9. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -171,8 +171,8 @@ not(expression) // evaluates a boolean expression and returns the opposite valu
    // 11.4. Node.


    lang(string) // determines whether the context node matches the given language and returns boolean true or false.
    name([node-set]) // returns a string representing the QName of the first node in a given node-set.
    lang(string) // determines whether the context node matches the given language and returns boolean true or false.
    name([node-set]) // returns a string representing the QName of the first node in a given node-set.
    namespace-uri([node-set]) // returns a string representing the namespace URI of the first node in a given node-set.


  10. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -171,10 +171,9 @@ not(expression) // evaluates a boolean expression and returns the opposite valu
    // 11.4. Node.


    lang(string) //
    name([node-set]) //
    namespace-uri([node-set]) //
    text() //
    lang(string) // determines whether the context node matches the given language and returns boolean true or false.
    name([node-set]) // returns a string representing the QName of the first node in a given node-set.
    namespace-uri([node-set]) // returns a string representing the namespace URI of the first node in a given node-set.


    // 11.5. Context.
  11. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -163,9 +163,9 @@ sum(node-set) // returns a number that is the sum of the numeric values of ea
    // 11.3. Logic.


    true() //
    false() //
    not(expr) //
    true() // returns a boolean value of true.
    false() // returns boolean false.
    not(expression) // evaluates a boolean expression and returns the opposite value.


    // 11.4. Node.
  12. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -147,17 +147,17 @@


    boolean(expression) // evaluates an expression and returns true or false.
    string([object]) // converts the given argument to a string.
    number([object]) // converts an object to a number and returns the number.
    string([object]) // converts the given argument to a string.
    number([object]) // converts an object to a number and returns the number.


    // 11.2. Math.


    ceiling(number) //
    floor(number) //
    round(decimal) //
    sum(node-set) //
    ceiling(number) // evaluates a decimal number and returns the smallest integer greater than or equal to the decimal number.
    floor(number) // evaluates a decimal number and returns the largest integer less than or equal to the decimal number.
    round(decimal) // returns a number that is the nearest integer to the given number.
    sum(node-set) // returns a number that is the sum of the numeric values of each node in a given node-set.


    // 11.3. Logic.
  13. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -147,8 +147,8 @@


    boolean(expression) // evaluates an expression and returns true or false.
    string([object]) //
    number([object]) //
    string([object]) // converts the given argument to a string.
    number([object]) // converts an object to a number and returns the number.


    // 11.2. Math.
  14. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 57 additions and 0 deletions.
    57 changes: 57 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -139,6 +139,63 @@
    '//*[@checked]' // checkbox (or radio button) that is checked (css: *:checked)


    // 11. XPath Functions.
    // https://developer.mozilla.org/en-US/docs/Web/XPath/Functions


    // 11.1. Conversion.


    boolean(expression) // evaluates an expression and returns true or false.
    string([object]) //
    number([object]) //


    // 11.2. Math.


    ceiling(number) //
    floor(number) //
    round(decimal) //
    sum(node-set) //


    // 11.3. Logic.


    true() //
    false() //
    not(expr) //


    // 11.4. Node.


    lang(string) //
    name([node-set]) //
    namespace-uri([node-set]) //
    text() //


    // 11.5. Context.


    count(node-set) //
    function-available(name) //
    last() //
    position() //


    // 11.6. String.


    contains(haystack-string, needle-string) //
    concat(string1, string2 [stringn]*) //
    normalize-space(string) //
    starts-with(haystack ,needle) //
    string-length([string]) //
    substring(string, start [length]) //
    substring-after(haystack, needle) //
    substring-before(haystack, needle) //
    translate( string, abc, XYZ) //

  15. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@


    // 0. XPath Examples.
    // More: http://xpath.alephzarro.com/content/cheatsheet.html


    '//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
  16. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,23 @@
    // http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/


    // 0. XPath Examples.


    '//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
    '//table[count(tr)=1 and count(tr/td)=2]' // all tables with 1 row and 2 cols
    '//div/form/parent::*' // all divs that have form
    './div/b' // a relative path
    '//table[parent::div[@class="pad"] and not(@id)]//a' // any anchor in a table without id, contained in a div of "pad" class
    '/html/body/div/*[preceding-sibling::h4]' // give me whatever after h4
    '//tr/td[font[@class="head" and text()="TRACK"]]' // all td that has font of a "head" class and text "TRACK"
    './table/tr[last()]' // the last row of a table
    '//rdf:Seq/rdf:li/em:id' // using namespaces
    '//a/@href' // hrefs of all anchors
    '//*[count(*)=3]' // all nodes with 3 children
    '//var|//acronym' // all vars and acronyms


    // 1. General.


  17. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // XPath CheatSheet
    // To test XPath in Chrome Debugger: $x('/html/body')
    // To test XPath in your Chrome Debugger: $x('/html/body')
    // http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/


  18. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    // XPath CheatSheet
    // To test XPath in Chrome Debugger: $x('/html/body')
    // http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/


    // 1. General.
  19. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -114,4 +114,11 @@
    // 10. Dynamic.


    '//E[@disabled]' // user interface element <E> that is disabled (css: E:disabled)
    '//*[not(@disabled)]' // user interface element that is enabled (css: E:enabled)
    '//*[@checked]' // checkbox (or radio button) that is checked (css: *:checked)





  20. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -106,8 +106,12 @@
    // 9. Table Cell.


    '//*[@id="TestTable"]//tr[3]//td[2]' // cell by row and column (e.g. 3rd row, 2nd column) (css: )
    '//*[@id="TestTable"]//tr[3]//td[2]' // cell by row and column (e.g. 3rd row, 2nd column) (css: #TestTable tr:nth-child(3) td:nth-child(2))
    '//td[preceding-sibling::td="t"]' // cell immediately following cell containing 't' exactly
    'td[preceding-sibling::td[contains(.,"t")]]' // cell immediately following cell containing 't'
    'td[preceding-sibling::td[contains(.,"t")]]' // cell immediately following cell containing 't' (css: td:contains('t') ~ td)


    // 10. Dynamic.



  21. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -105,3 +105,9 @@

    // 9. Table Cell.


    '//*[@id="TestTable"]//tr[3]//td[2]' // cell by row and column (e.g. 3rd row, 2nd column) (css: )
    '//td[preceding-sibling::td="t"]' // cell immediately following cell containing 't' exactly
    'td[preceding-sibling::td[contains(.,"t")]]' // cell immediately following cell containing 't'


  22. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -85,22 +85,22 @@
    '//*[@id="I"]//E' // descendant <E> of element with id I using unspecified path (css: #I E)
    '//E[count(*)=0]' // element <E> with no children (E:empty)
    '//E[count(*)=1]' // element <E> with an only child
    '//E[count(preceding-sibling::*)+count(following-sibling::*)=0]' // Element <E> that is an only child (css: E:only-child)
    '//E[count(../E) = 1]' // Element <E> with no <E> siblings (css: E:only-of-type)
    '//E[position() mod N = M + 1]' // Every Nth element starting with the (M+1)th (css: E:nth-child(Nn+M))
    '//E[count(preceding-sibling::*)+count(following-sibling::*)=0]' // element <E> that is an only child (css: E:only-child)
    '//E[count(../E) = 1]' // element <E> with no <E> siblings (css: E:only-of-type)
    '//E[position() mod N = M + 1]' // every Nth element starting with the (M+1)th (css: E:nth-child(Nn+M))


    // 8. Sibling.


    '//E2/following-sibling::E1' // Element <E1> following some sibling <E2> (css: E2 ~ E1)
    '//E2/following-sibling::*[1][name()="E1"]' // Element <E1> immediately following sibling <E2> (css: E2 + E1)
    '//E2/following-sibling::*[2][name()="E1"]' // Element <E1> following sibling <E2> with one intermediary (css: E2 + * + E1)
    '//E/following-sibling::*' // Sibling element immediately following <E> (css: E + *)
    '//E2/preceding-sibling::E1' // Element <E1> preceding some sibling <E2>
    '//E2/preceding-sibling::*[1][name()="E1"]' // Element <E1> immediately preceding sibling <E2>
    '//E2/preceding-sibling::*[2][name()="E1"]' // Element <E1> preceding sibling <E2> with one intermediary
    '//E/preceding-sibling::*[1]' // Sibling element immediately preceding <E>
    '//E2/following-sibling::E1' // element <E1> following some sibling <E2> (css: E2 ~ E1)
    '//E2/following-sibling::*[1][name()="E1"]' // element <E1> immediately following sibling <E2> (css: E2 + E1)
    '//E2/following-sibling::*[2][name()="E1"]' // element <E1> following sibling <E2> with one intermediary (css: E2 + * + E1)
    '//E/following-sibling::*' // sibling element immediately following <E> (css: E + *)
    '//E2/preceding-sibling::E1' // element <E1> preceding some sibling <E2>
    '//E2/preceding-sibling::*[1][name()="E1"]' // element <E1> immediately preceding sibling <E2>
    '//E2/preceding-sibling::*[2][name()="E1"]' // element <E1> preceding sibling <E2> with one intermediary
    '//E/preceding-sibling::*[1]' // sibling element immediately preceding <E>


    // 9. Table Cell.
  23. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -97,3 +97,11 @@
    '//E2/following-sibling::*[1][name()="E1"]' // Element <E1> immediately following sibling <E2> (css: E2 + E1)
    '//E2/following-sibling::*[2][name()="E1"]' // Element <E1> following sibling <E2> with one intermediary (css: E2 + * + E1)
    '//E/following-sibling::*' // Sibling element immediately following <E> (css: E + *)
    '//E2/preceding-sibling::E1' // Element <E1> preceding some sibling <E2>
    '//E2/preceding-sibling::*[1][name()="E1"]' // Element <E1> immediately preceding sibling <E2>
    '//E2/preceding-sibling::*[2][name()="E1"]' // Element <E1> preceding sibling <E2> with one intermediary
    '//E/preceding-sibling::*[1]' // Sibling element immediately preceding <E>


    // 9. Table Cell.

  24. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -93,3 +93,7 @@
    // 8. Sibling.


    '//E2/following-sibling::E1' // Element <E1> following some sibling <E2> (css: E2 ~ E1)
    '//E2/following-sibling::*[1][name()="E1"]' // Element <E1> immediately following sibling <E2> (css: E2 + E1)
    '//E2/following-sibling::*[2][name()="E1"]' // Element <E1> following sibling <E2> with one intermediary (css: E2 + * + E1)
    '//E/following-sibling::*' // Sibling element immediately following <E> (css: E + *)
  25. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -89,3 +89,7 @@
    '//E[count(../E) = 1]' // Element <E> with no <E> siblings (css: E:only-of-type)
    '//E[position() mod N = M + 1]' // Every Nth element starting with the (M+1)th (css: E:nth-child(Nn+M))


    // 8. Sibling.


  26. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 17 additions and 8 deletions.
    25 changes: 17 additions & 8 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -71,12 +71,21 @@
    // 7. Parent & Child.


    '//E/*[1]' // first child of element <E> (css: E > *:first-child)
    '//E[1]' // first <E> child (css: E:first-of-type)
    '//E/*[last()]' // last child of element E (css: E *:last-child)
    '//E[last()]' // last <E> child (css: E:last-of-type)
    '//E[2]' // second <E> child (css: E:nth-of-type(2))
    '//*[2][name()="E"]' // second child that is an <E> element (css: E:nth-child(2))
    '//E[last()-1]' // second-to-last <E> child (css: E:nth-last-of-type(2))

    '//E/*[1]' // first child of element <E> (css: E > *:first-child)
    '//E[1]' // first <E> child (css: E:first-of-type)
    '//E/*[last()]' // last child of element E (css: E *:last-child)
    '//E[last()]' // last <E> child (css: E:last-of-type)
    '//E[2]' // second <E> child (css: E:nth-of-type(2))
    '//*[2][name()="E"]' // second child that is an <E> element (css: E:nth-child(2))
    '//E[last()-1]' // second-to-last <E> child (css: E:nth-last-of-type(2))
    '//*[last()-1][name()="E"]' // second-to-last child that is an <E> element (css: E:nth-last-child(2))
    '//E1/[E2 and not( *[not(self::E2)])]' // element <E1> with only <E2> children
    '//E/..' // parent of element <E>
    '//*[@id="I"]/.../.../.../E' // descendant <E> of element with id I using specific path (css: #I > … > … > … > E)
    '//*[@id="I"]//E' // descendant <E> of element with id I using unspecified path (css: #I E)
    '//E[count(*)=0]' // element <E> with no children (E:empty)
    '//E[count(*)=1]' // element <E> with an only child
    '//E[count(preceding-sibling::*)+count(following-sibling::*)=0]' // Element <E> that is an only child (css: E:only-child)
    '//E[count(../E) = 1]' // Element <E> with no <E> siblings (css: E:only-of-type)
    '//E[position() mod N = M + 1]' // Every Nth element starting with the (M+1)th (css: E:nth-child(Nn+M))

  27. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -71,7 +71,12 @@
    // 7. Parent & Child.


    '//E/*[1]' // first child of element <E> (css: E > *:first-child)
    '//E[1]' // first <E> child (css: E:first-of-type)
    ''
    '//E/*[1]' // first child of element <E> (css: E > *:first-child)
    '//E[1]' // first <E> child (css: E:first-of-type)
    '//E/*[last()]' // last child of element E (css: E *:last-child)
    '//E[last()]' // last <E> child (css: E:last-of-type)
    '//E[2]' // second <E> child (css: E:nth-of-type(2))
    '//*[2][name()="E"]' // second child that is an <E> element (css: E:nth-child(2))
    '//E[last()-1]' // second-to-last <E> child (css: E:nth-last-of-type(2))


  28. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -66,3 +66,12 @@
    '//a[contains(text(), "t")]' // element <a> containing text 't' (css: a:contains('t'))
    '//a[@href="url"]' // <a> with target link 'url' (css: a[href='url'])
    '//a[.="t"]/@href' // link URL labeled with text 't' exactly


    // 7. Parent & Child.


    '//E/*[1]' // first child of element <E> (css: E > *:first-child)
    '//E[1]' // first <E> child (css: E:first-of-type)
    ''

  29. Julien Le Coupanec revised this gist Jul 25, 2014. No changes.
  30. Julien Le Coupanec revised this gist Jul 25, 2014. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion xpath-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -56,4 +56,13 @@
    '//E[contains(concat(" ", @class, " "), " C ")]' // element <E> with a class C (css: E.C)


    // 6. Text & Link.
    // 6. Text & Link.


    '//*[.="t"]' // element containing text 't' exactly
    '//E[contains(text(), "t")]' // element <E> containing text 't' (css: E:contains('t'))
    '//a' // link element (css: a)
    '//a[.="t"]' // element <a> containing text 't' exactly
    '//a[contains(text(), "t")]' // element <a> containing text 't' (css: a:contains('t'))
    '//a[@href="url"]' // <a> with target link 'url' (css: a[href='url'])
    '//a[.="t"]/@href' // link URL labeled with text 't' exactly