What is xpath?
It is a technique to navigate through the HTML structure of path.
In simple terms, It is a location of any element of a webpage.
Types of XPath?
- Absolute xpath
- Relative xpath
Relative xpath : does not depend on parent nodes (starts with // ) – recommended to use.
Absolute xpath : Complete path from root(parent) till required element(child). (starts with / html)
What is cssSelector?
It is an address of of an element
Difference between xpath and cssSelector?
| xpath | cssSelector |
|---|---|
| xPath is slower than css selector | CSS is faster than xpath |
| XPath we can traverse both forward and backward | CSS selector only moves forward |
| xpath based on xml query | cssSelector based on properties of an element. |
| ‘text’ can be used to write the xpath. | We can use properties and attributes names, but not text. |
| Do not support shadow DOM | support shadow DOM |
Functions of cssSelector
- #idValue
- .classValue
- tagName
- tagName[attrName=”attrValue”]
- tagName[attr=”value1″][@attr=”value2″]
- tagName[attributeName$=’ending value of attribute’]
- tagName[attributeName^=’starting value of attribute’]
- tagName[attributeName*=’sub-string value of attribute’]
- Case insensitive i
Official website :
https://selectorshub.com/
Udemy free video:
https://www.udemy.com/course/xpath-tutorial-from-basic-to-advance-level/
https://www.udemy.com/course/cssselector-tutorial-from-basic-to-advance-level
xPath and cssSelector functions and error handling :
https://selectorshub.com/xpath-and-cssselector-functions/