XPath and cssSelectors

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?

  1. Absolute xpath
  2. 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?

xpathcssSelector
xPath is slower than css selectorCSS is faster than xpath
XPath we can traverse both forward and backwardCSS selector only moves forward
xpath based on xml querycssSelector 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/

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.