Xpath is known as the navigation through the html sytax of a webpage to identify a particular element
Any webelement in an application will be assinged with an identifier.
The web elements will have attributes as well as the identifiers listed below
With the above identifiers elements can be identified and can be automated to perform certain set of actions
Reasons to go with Xpath:
1. Some complex applications like AJAX, GWT willdynamically create some identities for the web elements where the
identification becomes difficulty during the automation of an application.
2. In certain scenarios there may be situations where different web elements have same Name and ID even.
where it becomes difficult for any automation tool to perform the actions given.
In above scenarios the alternate solution is "Xpath"
*Xpath is the way of identifying the web elements uniquely.*
Approaches for Xapth:
There are two ways of defining Xpath for web elements, they are listed below
Defining the Xapth by just giving the navigation through the html path to the web elements.
The above appoach is good only if there are no new addition of features in the application, but if any new
features added then the xpath fails here.
2. Non-Dependency/Unique :
Defining the Xapth uniquely which works even if any new web elements added to the application anytime
Some commonly used used commands for writing Xpath for webelemnts:
1. // - Selects nodes in the document from the current node that match the selection no matter where they are
2. / - Selects from the root node
3. * - Matches any element node
4. .. - Selects the parent of the current node
5.@ - Selects attributes
Tools used for finding Xpath for web elements:
* Firebug(Add-on for Mozilla browser)
* IEdeveloper(Addon for IE explorer)
* Xpather(Add-on for Mozilla browser)
* XFinder(Add-on for Mozilla browser)