Most Exhaustive XPath Locators Cheat Sheet
Most Exhaustive XPath Locators Cheat Sheet
Most Exhaustive XPath Locators Cheat Sheet
//img/*[1] first child of element img //img[@id!='myId'] image elements with @id not equal to
'myId'
//ul/child::li first child 'li' of 'ul'
//img[@name] image elements that have name attribute
//img[1] first img child
//*[contains(@id, 'Id')] element with @id containing
//img/*[last()] last child of element img
//*[starts-with(@id, 'Id')] element with @id starting with
//img[last()] last img child
//*[ends-with(@id, 'Id')] element with @id ending with
//img[last()-1] second last img child
//*[matches(@id, 'r')] element with @id matching regex ‘r’
//ul[*] ul' that has children
//*[@name='myName'] image element with @name= 'myName'
//table[count(tr) > 1] return table with more than //td[preceding-sibling::td="t"] cell immediately following
1 row cell containing 't' exactly
//a[contains(text(), "Log Out")] anchor with inner text //input/following-sibling::a 'a' following some sibling
containing 'Log Out' 'input'
//a[not(contains(text(), "Log Out"))] anchor with inner text not //a/following-sibling::* sibling element
containing 'Log Out' immediately following 'a'
//a[not(@disabled)] all 'a' elements that are not //input/preceding-sibling::a 'a' preceding some sibling
disabled 'input'
String Methods
LOCATOR EXPLANATION
contains(space-string, planet-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(spacetrack, space) checks whether the first string starts with the second string and returns true or false
substring-after(spacetrack, track) returns a string that is the rest of a given string after a given substring
substring-before(spacetrack, tra) returns a string that is the rest of a given string before a given substring
translate(string, ghj, GHJ) evaluates a string and a set of characters to translate and returns the translated string