Find xpath with following-siblings and contains text in Python Selenium

656 Views Asked by At

I know the very basics of using following-siblings but here I have a situation where it looks a bit more complicated.

I want to find the element with text Total 6.5 where the header is Total games. How can I do it with following-siblings and contains text?

<div class="group">
 <div class="header_1">
  <div class="section_1">
   <div class="expander"></div>
   <div class="star"></div>
   <div class="text_3">Total games</div>
  </div>
 </div>
 <div class="body_1">
  <div class="horizontal">
   <div class="grid">
    <div class="row_common">
     <div class="cell_wrap">
      <div class="cell_align_wrap">
       <div class="common_text">Total 6.5</div>
      </div>
     </div>
    </div>
    <div class="row_common">
    ...
    </div>
   </div>
  </div>
 </div>
</div>
1

There are 1 best solutions below

0
On BEST ANSWER

This one should locate required element

//div[@class="header_1" and contains(., "Total games")]/following-sibling::div[@class="body_1"]//div[@class="common_text"]

you can also simplify it as

//div[@class="header_1" and contains(., "Total games")]/following::div[@class="common_text"]