2016-05-31 227 views
-2

我正在嘗試檢索父(grand-grand-parent)元素的id。Robot Framework:如何獲取元素的xpath?

我得到的所有信息是// div [@ class =「preset_name」]是「all」。知道這一點,我需要使用任何Robot Framework關鍵字檢索「preset_3」(作爲字符串)。 我該怎麼做?或者我怎樣才能獲得「全部」的完整xpath?

<table id="preset_list"> 
 
    <tbody> 
 
    <tr id="preset_0"> 
 
     <td> 
 
     <div class="preset_title_line"> 
 
      <div class="preset_button_group"> 
 
      <button class="preset_button">Apply</button> 
 
      </div> 
 
      <div class="preset_name">Factory default</div> 
 
     </div> 
 
     <div class="preset_sections">System, Network, Sources, EDID, Channels, Automatic File Upload, Touch screen, Output ports</div> 
 
     </td> 
 
    </tr> 
 
    <tr id="preset_1"> 
 
     <td> 
 
     ...

+1

到OP:請絕對不要發佈XML/HTML(或任何類型的代碼)的圖像。改爲發佈文字。後者更有用,因爲人們可以使用它來測試他們的XPath。謝謝 – har07

+0

告訴我們你已經嘗試過了。這看起來像是一個相對直接的問題,可以用簡單的xpath表達式來解決。 –

回答

0

你的XPath應該是:

Get Element Attribute xpath=(//div[@class="preset_name"][text()='all']/../../..)@id 

(我從來沒有用過的機器人,但我認爲這是正確的sintax)

+0

「獲取元素屬性」後缺少空格 - 在此機器人語法中,關鍵字和參數由兩個或多個空格分隔。 –

+0

@BryanOakley謝謝,我修復了代碼 –

+0

@StriterAlfa非常感謝! –

0

可以過濾tr包含//div[@class="preset_name"] = "all",然後返回相應的id屬性:

//tr[.//div[@class='present_name'] = 'all']/@id 
+0

非常感謝! –