Reverse XPath - Finding the xpath of a element using bottom up approach
By thekkadath on Jul 25, 2008
Assume that we need to find the xpath of a link "Login" appearing in a webpage. Usually when we find xpath of a GUI element, we normally follow a top-down approach, meaning the xpath is recorded from the parent level to the child. But there is also a bottom up approach, where in you can begin from a inner child element and navigate all the way up till the GUI element is reached.
Below is the corresponding xml code and various method of finding XPath of "Login" link. The bottom-up approach is explained by note (e) in the below table.
| Sample XML Code
(a) Using Top Down approach starting from a top node
(b) Directly accessing the child node using its text value
(c) Directly accessing the child node using child's attribute value
Directly accessing the child node using wildcard search. All occurences
of text "Logi\*" is matched by below xpath.It will work in this example
since there is only one text "Login" which has occurence "Logi" in it.
Using Bottom Up approach starting from another child node and
navigating to the actual node. Note: Here the DOM structure should be
maintained (as it is in the xml) between the start node and end node