Home > Back-end >  XPath: how to navigate from a child to another child of the same parent
XPath: how to navigate from a child to another child of the same parent

Time:09-17

I have the following HTML:

<div _ngcontent-yei-c89="" class="folder-content__tile-view"><div _ngcontent-yei-c89="" class="widget">
 <div _ngcontent-yei-c89="" soho-widget-header="" class="widget-header">
  <button _ngcontent-yei-c89="" soho-button="icon" icon="more" soho-context-menu="" menu="action-popupmenu" trigger="click" class="btn-actions btn-icon has-tooltip" type="button" aria-pressed="false" aria-haspopup="true" aria-controls="action-popupmenu">
   <svg soho-icon="" aria-hidden="true" focusable="false" role="presentation" class="icon">
    <use href="#icon-more"></use>
   </svg>
   <!---->
   <span></span>
  </button><!----><!----></div>
 <div _ngcontent-yei-c89="" soho-widget-content="" class="widget-content"><!----><!---->
  <svg _ngcontent-yei-c89="" soho-icon="" icon="map" aria-hidden="true" focusable="false" role="presentation" class="icon">
   <use href="#icon-map"></use>
  </svg><!----><!---->
  <h1 _ngcontent-yei-c89="" soho-tooltip="" class="ellipsis has-tooltip">Process Map</h1>
  <h2 _ngcontent-yei-c89=""> Sep 14, 2021, 11:47:25 AM </h2>
 </div>
</div>

I would like to get the xpath of the <button> by using the icon as unique id: //*[local-name()='svg'][*[local-name()='use'][@href="#icon-map"]]. This path works but I am not sure how to get the button from here.

CodePudding user response:

You are over-complicating the xpath

//button[@menu="action-popupmenu"] 

you can use any other attribute like this

the icon-map svg is not at all related to the button , but if you still want to use it then :

//*[local-name()='svg'][*[local-name()='use'][@href="#icon-map"]]/../preceding-sibling::div/button
  • Related