xpath is xml path language, and selenium uses xpath as one of the locator strategies to locate web element[s] from the DOM (document object model).
DOM is nothing but the tree structure of the html / xml document.
xpath normally provides the path to navigate to the required element from the tree structure.
xpath types : Absolute & Relative
Need to provide complete path of the required web element, starting from the root element.
Example: gmail sign in page… find the Email field
As you can see, each tag is separated by a “/”, means they are immediate element to each other.
This is sometimes risky to use, as in real time web applications, the DOM structure changes frequently or if some elements in DOM changed on the way from root to desired element, then absolute xpath will not work.
But in case, where there is no specific attributes to locate the element such as id/name, then we can use the absolute xpath (may be the last solution to locate)…