How to find the Parent from a Child node in reverse order ?

64 views
Skip to first unread message

QA Rampage

unread,
Jan 18, 2016, 12:10:37 PM1/18/16
to Selenium Users
Assuming the following HTML source attached here with - Sample.html

NOTE:
 1) All the  "...." means there can be any number of TAG in between
 2) All the reference A, B are merely reference. These will be duplicate entries so Xpath is not created based on that.


WHEN  xPath = (//span[@class='node-type-button'])[1]    , THEN results is  First instance     <span class=node-type-button> ...B...... </span>    ===> PERFECT

Now, what is needed  -
1)  to go in the Reverse search order and find that particular parent of the above result  having       <div class="wrapper">   reference with A 

/.. will not help, because the intended DIV is not just-the-previous item 

How to find that ?
Sample.html

Shashi

unread,
Jan 18, 2016, 1:50:43 PM1/18/16
to Selenium Users
You should be able to use xpath axis "ancestor" to accomplish what you need.  

There is a tutorial on XPath axes on the W3C website:  http://www.w3schools.com/xsl/xpath_axes.asp

There are also numerous blog posts on the Internet on how to use axes for locating Selenium elements.  Here is one (it is not the only one): http://www.seleniumeasy.com/selenium-tutorials/xpath-tutorial-for-selenium

Hope that helps,
Shashi

QA Rampage

unread,
Jan 18, 2016, 10:43:22 PM1/18/16
to Selenium Users
Thanks it helped :)
Reply all
Reply to author
Forward
0 new messages