Xpath Locators Flashcards
Xpath uses path expressions to…
identify and navigate nodes in an XML document.
xpath expressions are related to…
path expressions in traditional computer file system.
Xpath predicates
Are used to find a specific element or an element that contains a specific value.
Xpath wildcards
Can be used to select XML nodes based on a specified criteria.
Path Expression: TheNode
Selects all elements with name “TheNode”
Path Expression: /
Selects the root element.
Path Expression: //
Returns descendants of the current element.
Path Expression: .
Returns the current element.
Path Expression: ..
Selects the parent of the current element.
Path Expression: @
Selects an attribute of the current element.
Xpath wildcard: *
Matches any element node.
Xpath wildcard: @*
Matches any attribute node.
Xpath wildcard: Node()
Matches any node of any kind.
XPATH EXPRESSION: Magazines
Selects all nodes with the name “Magazines”
XPATH EXPRESSION: /Magazines
Selects the root element “Magazines”
XPATH EXPRESSION:Magazines/Magazine
Selects all Magazine elements of Magazines
XPATH EXPRESSION://Magazines
Selects all Magazine elements in the document
PATH EXPRESSION:Magazines//Magazine
Selects all Magazine elements that are descendants of Magazines
XPATH EXPRESSION://@lang
Selects all attributes named lang
XPATH EXPRESSION:Selects the first Magazine element
/Magazines/Magazine[1]
XPATH EXPRESSION:/Magazines/Magazine[last()]
Selects the last child Magazine element
XPATH EXPRESSION:/Magazines/Magazine[last()-1]
Selects the second to last Magazine element
XPATH EXPRESSION://title[@lang]
Selects all title elements with attribute “lang”
XPATH EXPRESSION://title[@lang=’en’]
Selects all title elements with attribute lang=en
XPATH OPERATOR: //Magazine | //CD
Selects multiple paths
XPATH OPERATOR: price>3.00 or lang=”en”
or Or
XPATH OPERATOR: price>3.00 and lang=”en”
and And
XPATH OPERATOR: not lang=”en”
not Invert
XPATH OPERATOR: “en” || “glish”
|| String concatenation
XPATH FUNCTION: string(arg)
Returns string value of the argument
XPATH FUNCTION: substring(str, start, len)
Returns a substring of a string of length “len” starting at “start”
XPATH FUNCTION:string-length(str)
Returns the length of the string. If there is no argument passed in, returns length of current node
XPATH FUNCTION:compare(str1, str2)
Returns -1 if str1 < str2, 0 if strings are equal, +1 if str1 > Str2
XPATH FUNCTION:concat(str1, str2, …)
Returns a concatenation of all strings inputted
XPATH FUNCTION:upper-case(str)
inputted upper-case(str)
XPATH FUNCTION:lower-case(str)
Converts the string argument to lower case
XPATH FUNCTION:contains(str1, str2)
Returns TRUE if str1 contains str2
XPATH FUNCTION:starts-with(str1, str2)
Returns TRUE if str1 starts with str2
XPATH FUNCTION: ends-with(str1, str2)
Returns TRUE if str1 ends with str2
XPATH OPERATOR:div Division
14 div 2
XPATH OPERATOR:mod Modulus (remainder after division)
7 mod 3
XPATH OPERATOR: