Definition – Xpath stands for XMLPath Language where XML is eXtensible Markup Language. Xpath contains over 50+ built-in functions, which are used in locating webobjects.
We have learned different Xpath methods in our earlier post. In this post, we will cover X-Path Relationships, Axes of Xpath etc.
Syntax for XPath:
XPath contains the path of the webelement situated at the web page. The standard syntax for creating XPath is.
•// : Selection of current node.
•Tagname: Tagname of the that designated node.
• @: Select attribute.
• Attribute: Attribute name of the node.
• Value: Attribute Value.
Relationship of Nodes: Below are the widely used relationship in Xpath
Useful functions: Some of the useful Xpath functions are-
Please refer below diagram, which will help in understanding Xpath Axes’s.
This is an example of a company, where the Department, Team, and Employee are taken. Assume this as HTML components
Summary– Xpath is most preferred while a direct(Id, Name) object property is not available as Xpath has various ways to form/calculate than Css-Selector.
Now Question is which one is better- My recommendation is –
1- Use CssSelector when cross-browser scripts are required as X-path may vary in different browser
2- Use Xpath when Objects are lying under a table
3- Both of them perform almost similar in speed/search.