ExecuteAutomation

Understanding and working with Xpath

In this post we will discuss understanding and working with Xpath and how to use the same in selenium.

What is Xpath

We are not going to deal with the theory of Xpath, which you can always get from lot of website and the best of them all is w3school.

Working on xpath

Locating element with xpath

Xpath can be formed either by hand coding, if you have good knowledge on the structure of the page or by using tools like Firepath etc

Some common Xpath tidbits

Xpath Meaning
/ Selects from the root node
// Selects nodes in the document from the current node that match the selection no matter where they are
//*[@id=’fbt_x_check’] Selecting with the attribute
//*[@id=’sims_fbt’]/descendant::div Selecting all descendant divs from current node
//*[@id=’sims_fbt’]/descendant::div[last()] Selecting the last div from the current node which is descendant (Used Predicate as well !!!)
//*[@id=’fbt_x_check’]/following-sibling::div Selecting next sibling from current node
  Here is the complete video of the above discussion Thanks for watching the video !!! Please let me know if you have any questions from the above video. Thanks, Karthik KK