Reverse XPath - Finding the xpath of a element using bottom up approach

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
XPath

(a) Using Top Down approach starting from a top node 
//table/tr/a[text()='Login']

(b) Directly accessing the child node using its text value
//a[text()='Login']

(c) Directly accessing the child node using child's attribute value
//a[@href='1.html']

(d) 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.
//a[contains(text(),'Logi')] 

(e) 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
//a[text()='Home']/../../../table/tr/a[text()='Login']


dsds



Comments:

Post a Comment:
Comments are closed for this entry.
About

I'm a Quality Engineer at Sun Microsystems. Here in this blog, you may find information about Software Testing, Portal Server, Virtualization, Web2.0 and Misc Technical topics. The views expressed here are personal and does not reflect that of my employer

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today