XPath & CSS Selector
Cheat Sheet
XPath
• //TagName[@AttributeName='AttributeValue']
• //TagName[@AttributeName='AttributeValue'][@AttributeName='AttributeValue']
• //TagName[@AttributeName='AttributeValue' and @AttributeName='AttributeValue']
• //TagName[@AttributeName='AttributeValue' or @AttributeName='AttributeValue']
• //TagName[@AttributeName='AttributeValue']/TagName[n]/TagName[n]
XPath Partial Pattern Match - //TagName[PartialPatternMatch(@AttributeName,'AttributeValue')]
• //TagName[starts-with(@AttributeName,'AttributeValue')]
• //TagName[contains(@AttributeName,'AttributeValue')]
XPath Search For Text
• //TagName[text()='Value']
XPath Axes
• //TagName[text()='Value']//preceding::TagName[n]
• //TagName[@AttributeName='AttributeValue']//preceding::TagName[n]
• //TagName[text()='Value']//following::TagName[n]
• //TagName[@AttributeName='AttributeValue']//following::TagName[n]
CSS
CSS Syntax (* = any TagName / # (pound) = ID AttributeName / . (dot) = Class AttributeName)
• TagName#AttributeValue
• TagName.AttributeValue
• TagName[AttributeName='AttributeValue']
• TagName[AttributeName='AttributeValue'][AttributeName='AttributeValue']
CSS nth-child(n) Syntax
• TagName[AttributeName='AttributeValue'] TagName TagName:nth-child(n) TagName
CSS Child Select (> = Parent-Child Relationship)
• TagName.AttributeValue > TagName.AttributeValue
• TagName.AttributeValue > TagName#AttributeValue