2017-10-20 87 views
0

我想訪問包含文本'未來20天的OODR項目'的class =='box-title'類名爲'table table-hover'的表。任何人都可以幫助我得到這個xpath嗎?我試着跟隨兄弟姐妹,但沒有運氣。提前致謝。xpath with following-sibling

<?xml version="1.0" encoding="UTF-8"?> 
 
<div id="topTenSellers" class="box box-solid box-primary frontpageWidget"> 
 
    <div class="box-header"> 
 
     <i class="fa fa-group" /> 
 
     <h3 class="box-title">OODR Items for next 20 Days</h3> 
 
     <div class="box-tools pull-right"> 
 
     <button class="btn btn-primary btn-sm" data-widget="collapse"> 
 
      <i class="fa fa-minus" /> 
 
     </button> 
 
     </div> 
 
    </div> 
 
    <!-- /.box-header --> 
 
    <div class="box-body no-padding"> 
 
     <table class="table table-hover"> 
 
     <tbody> 
 
      <tr> 
 
       <th style="width: 10px">#</th> 
 
       <th>Booking</th> 
 
       <th>Item Start Date</th> 
 
       <th>Site</th> 
 
       <th>Supplier</th> 
 
      </tr> 
 
      <tr> 
 
       <td> 
 
        <strong>1</strong> 
 
       </td> 
 
       <td> 
 
        <a href="" target="_blank">(642143)</a> 
 
       </td> 
 
       <td>21/10/2017 00:00:00</td> 
 
       <td>Ski</td> 
 
       <td>OODR - Out of Date Range</td> 
 
      </tr> 
 
     </tbody> 
 
     </table> 
 
    </div> 
 
    <!-- /.box-body --> 
 
</div>

+0

請提供xml,而不是圖片 – derloopkat

+0

對不起現在加入。 – Neela

回答

0

你可以試試following代替following-sibling提到h3table節點沒有兄弟姐妹:

//div[@id="topTenSellers"]//h3[@class="box-title" and .="OODR Items for next 20 Days"]/following::table[@class="table table-hover"] 
+0

謝謝安德森。它返回了5個元素。我在最後添加了[1],然後獲得了我需要的元素。 – Neela

+0

如果在頁面上有多個具有相同類名的'table'節點,您還可以嘗試'// div [@ id =「topTenSellers」和.//h3="OODR for next 20 Days「] // table [ @ class =「table table-hover」]' – Andersson

+0

謹慎@Neela,如果您的heiarchy中含有超過1個元素,則在末尾指定[1]仍然可能會導致多個元素。 將你的xpath包裹在()後緊跟着[1]以嚴格指定單個元素。 '(// div [@ id =「topTenSellers」] // h3 [@ class =「box-title」and。=「OODR Items for next 20 Days」]/following :: table [@ class =「table表懸停「])[1]' – Ben

0

如果只有一個類名的元素,則任這些將起作用。有一件事需要注意,硒可能會根據版本和瀏覽器在類名空間中掙扎。如果你發現這種情況,那麼使用多個包含來處理空格。

//table[contains(@class,'table table-hover')] 
//table[@class = 'table table-hover'] 

如果您需要的元素作爲OODR項目的20天內

//h3[contains(text(),'OODR Items for the next 20 days')]/parent::div/following-sibling::div/table[@class ='table table-hover'] 

孩子這個路徑使用你的錨點,「OODR項目..」,然後去了父母,然後兄弟姐妹,然後到具有指定類名的項目。祝你好運!