This shows you the differences between two versions of the page.
xpath [2018/01/04 10:29] tast |
xpath [2020/10/21 14:37] (current) montse |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== XPath object identification ===== | + | ====== XPath object identification ====== |
- | + | ||
- | [[doku>wiki:dokuwiki|{{wiki:TAST-128_small.png }}]] | + | |
In the following lines, the user will find tips for being able to identify the web objects via XPath. | In the following lines, the user will find tips for being able to identify the web objects via XPath. | ||
Line 12: | Line 10: | ||
Nevertheless, since this way can be too long, there are some ways to shorten it. For this, is necessary to know some syntax related to it: | Nevertheless, since this way can be too long, there are some ways to shorten it. For this, is necessary to know some syntax related to it: | ||
- | ^ XPath Expression ^ Description ^ Expression example ^ Example meaning^ | + | ^ XPath Expression ^ Description ^ Expression example ^ Example meaning ^ |
- | |/|Selects from the root node |(...)/b/a |Element "a" child of "b", child of "(...)"| | + | |/|Selects from the root node |(...)/b/a |Element "//a//" child of "//b//", child of "//(...)//"| |
- | |/ /|Selects any nodes from the current node that match the selection no matter where they are |b / / a(...)|All the "a(...)" elements child of "b".| | + | |/ /|Selects any nodes from the current node that match the selection no matter where they are |b / / a(...)|All the "//a(...)//" elements child of "//b//".| |
- | |* |Matches any element node (wildcard) |b / * / a |Any "a" element whose grandparent is "b"| | + | |* |Matches any element node (wildcard) |b / * / a |Any "//a//" element whose grandparent is "//b//"| |
- | |. |Selects the current node |./ /de |Any "de" element that is one or more levels inside the current node| | + | |. |Selects the current node |./ /de |Any "//de//" element that is one or more levels inside the current node| |
- | |.. |Selects the parent of the current node |abc[../mg] |Any "abc" element that has a "mg" sibling| | + | |.. |Selects the parent of the current node |abc[../mg] |Any "//abc//" element that has a "//mg//" sibling| |
- | |@ |Selects attributes |a[@bcd] |"a" element with a "bcd" attribute| | + | |@ |Selects attributes |a[@bcd] |"//a//" element with a "//bcd//" attribute| |
- | |@ = |Selects attributes with a value |a[@bcd="hola"] |"a" element with a "bcd" attribute equal to hola| | + | |@ = |Selects attributes with a value |a[@bcd="hola"] |"//a//" element with a "//bcd//" attribute equal to hola| |
- | |@* |Matches any attribute node |a[@*="hola"] |"a" element with any attribute equal to hola| | + | |@* |Matches any attribute node |a[@*="hola"] |"//a//" element with any attribute equal to //hola//| |
- | |last() |Matches the last element |b / a[last()] |The last "a" element child of "b"| | + | |last() |Matches the last element |b / a[last()] |The last "//a//" element child of "//b//"| |
- | |[] |Element that contains something |c[hello] / b[@a] |"b"element that contains an "a" attribute, child of a "c" that contains a hello element| | + | |[] |Element that contains something |c[hello] / b[@a] |"//b//" element that contains an "//a//" attribute, child of a "//c//" that contains a hello element| |
- | |[][] |Element that contains two things (or more, if more brackets are added) |a[@b][@c] |"a" element with both a "b" attribute and a "c" attribute| | + | |[][] |Element that contains two things (or more, if more brackets are added) |a[@b][@c] |"//a//" element with **both** a "//b//" attribute and a "//c//" attribute| |
- | |[n] |The n-th element |b/a[3] |The 3rd "a" element child of "b"| | + | |[n] |The n-th element |b/a[3] |The 3rd "//a//" element child of "//b//"| |
- | |!= |Not equal |a[@bcd!="hola"] |"a" element with a "bcd" attribute NOT equal to hola| | + | |!= |Not equal |a[@bcd!="hola"] |"//a//" element with a "//bcd//" attribute NOT equal to //hola//| |
- | |last() |Last element |b/a[last()] |the last "a" that is child of a "b"| | + | |last() |Last element |b/a[last()] |the last "//a//" that is child of a "//b//"| |
- | |() |Groups operations for establishing the priorities |(de/mg)[3] |the third entire set "de/mg"| | + | |() |Groups operations for establishing the priorities |(de/mg)[3] |the third entire set "//de/mg//"| |
- | |and |Logical AND as usual |a[b and c] |"a" element containing both "b" and "c"| | + | |and |Logical AND as usual |a[b and c] |"//a//" element containing **both** "//b//" and "//c//"| |
- | |or |Logical OR as usual |de[@mg or @dus] |"de" element containing a "mg" attribute or a "dus" attribute| | + | |or |Logical OR as usual |de[@mg or @dus] |"//de//" element containing a "//mg//" attribute or a "//dus//" attribute| |
- | |contains() |Matches all the elements that (partially) contains what is inside the brackets |de[contains(.,'click here')] |"de" elements with a text containing "click here"| | + | |contains() |Matches all the elements that (partially) contains what is inside the brackets |de[contains(.,'click here')] |"//de//" elements with a text containing "//click here//"| |
- | |starts-with() |Matches all the elements that start with what is inside the brackets |de[starts-with(@id,'id-name')] |"de"elements whose id starts with "id-name(...)"| | + | |starts-with() |Matches all the elements that start with what is inside the brackets |de[starts-with(@id,'id-name')] |"//de//"elements whose id starts with "//id-name(...)//"| |
- | |[ .=''] |Matches the elements with a string |de[.='string 1 of 6'] |"de" elements with the string "string 1 of 6"| | + | |[ .=''] |Matches the elements with a string |de[.='string 1 of 6'] |"//de//" elements with the string "//string 1 of 6//"| |
- | |normalize-space() |Matches the elements with a string, ignoring leading or trailing blank spaces |de[normalize-space()='mg'] |"de" elements with the string "mg" or " mg" or "mg " or " mg "| | + | |normalize-space() |Matches the elements with a string, ignoring leading or trailing blank spaces |de[normalize-space()='mg'] |"//de//" elements with the string "//mg//" or "// mg//" or "//mg //" or "// mg //"| |
- | |text() |Selects the elements with a specific text within |de[text()="mg"] |"de" elements with the string "mg" in the text field| | + | |text() |Selects the elements with a specific text within |de[text()="mg"] |"//de//" elements with the string "//mg//" in the text field| |
- | |[ / @ ] |Selects the elements that have specific children |/ /de[mg/@attr1='nrw'] |"de" elements which have a "mg" child with an attribute "attr1" equal to "nrw"| | + | |[ / @ ] |Selects the elements that have specific children| / / de[mg/@attr1='nrw']|"//de//" elements which have a "//mg//" child with an attribute "//attr1//" equal to "//nrw//"| |
+ | |||
+ | \\ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== How to Obtain Xpath in a XML document ===== | ||
+ | |||
+ | How to obtain the Xpath of the XML node with Notepad ++:\\ \\ | ||
+ | 1. Inside Notepad++ go to Plugins then go to Plugin Manager and click in Show Plugin Manager.\\ 2. Install XML Tools.\\ 3. Restart Notepad++.\\ 4. Load your XML document.\\ 5. Place your cursor on to the node you are looking to generate the Xpath.\\ 6. Go to plugins then XML Tools and select Current XML Plath (Default Hotkey: Ctrl + Alt + Shift + P).\\ \\ | ||
+ | Then you have a copy of the Xpath in the clipboard. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||