-1

<ul id="ul_id">
  <li id="f_li"><a href="#">First li</a>
    <ul id="f_li_ul_id">
      <li id="li_ul_li1"><a href="#">First li ul li</a></li>
      <li id="li_ul_li2"><a href="#">Second li ul li</a></li>
      <li id="li_ul_li3"><a href="#">Third li ul li</a></li>
    </ul>
  </li>
  <li id="s_li"><a href="#">Second li</a></li>
</ul>

I need to get f_li_ul_id from my current id li_ul_li2 and get ul_id from my current id s_li.

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
  • Try to find your answer in this Article: [https://stackoverflow.com/questions/24267413/how-to-get-parent-of-webelement](https://stackoverflow.com/questions/24267413/how-to-get-parent-of-webelement) – H0axD3 Dec 17 '18 at 11:38
  • i tried that my xpath is printing with /.. is not getting parent node – Priya Dharshan Dec 17 '18 at 11:41
  • 1
    Possible duplicate of [Select parent element of known element in Selenium](https://stackoverflow.com/questions/8577636/select-parent-element-of-known-element-in-selenium) – Moshe Slavin Dec 17 '18 at 14:10
  • see the answer: https://stackoverflow.com/a/45769799/8179099 – Moshe Slavin Dec 17 '18 at 14:11
  • The simplest way is like, `//ul[./li[@id='li_ul_li2']]` – JeffC Dec 17 '18 at 16:30

1 Answers1

0

If you want to reach at f_li_ul_id from li_ul_li2 , you can use this xpath :

//li[@id='li_ul_li2']/parent::ul[@id='f_li_ul_id']  

and for ul_id from s_li, you can write xpath like this :

//li[@id='s_li']/parent::ul[@id='ul_id']
cruisepandey
  • 28,520
  • 6
  • 20
  • 38