Sunday, 30 June 2013

Locate element using Xpath Axis

There will be some situations where using normal xpath did not work,in such case we can use xpath axes :


Following is the sample html code :

<html>
<body>
<div id='d1'>
    <div id='id2'>
    <input id='in1'>
    <input id='in2'>
    </div>
</div>
</body>
</html>

1. //input[@id='in1']/ancestor::div      Selects div having id=id2
2. //div[@id='id1']/descendant::div     Selects div having id=id2 

Note: By using above html code i tried to demonstrate the use of xpath axis. However by using simple xpath we can select any node from the above html.

No comments:

Post a Comment