2017-03-01 40 views
2

我想驗證某個特定元素的網頁上是否存在特定圖像。圖像:如何使用Robot Framework在特定元素內驗證圖像

  • 沒有唯一ID
  • 沒有唯一ALT
  • src屬性包含查詢字符串我試圖忽視
  • 頁面

上多次出現我不能使用頁面應該包含圖像,因爲它出現多次,但我需要驗證它出現在特定的表格單元格中。該圖片src看起來是這樣的:

${BaseUrl}/status_submitted.png?master_2017217_17-29 

這裏的周邊圖像的HTML:

<table id="mass_list" class="grid"> 
    <tr> 
    <th class="shrink align_center">Status</th> 
     <th>Action</th> 
     <th class="shrink align_right">Submitted</th> 
     <th class="shrink">Submitted By</th> 
    </tr> 
    <tr> 
      <td> 
       <img src="https://{baseurl}/images/status_submitted.png?master_2017217_17-29" alt="Submitted" width="70" height="20" /> 
      </td> 
      <td class="nowrap"> 
       Automation Test 1488321180.7 

       <br /> 
       <small class="mute"> 
        <strong>0</strong> of <strong>2</strong> records processed 
       </small> 

      </td> 
      <td class="nowrap align_right">Yesterday at 4:33 PM</td> 
      <td class="nowrap">Tina Tester</td> 
     </tr> 
     <tr> 
      <td> 
       <img src="https://{baseurl}/images/status_submitted.png?master_2017217_17-29" alt="Submitted" width="70" height="20" /> 
      </td> 
      <td class="nowrap"> 
       Add an attribute 

       <br /> 
       <small class="mute"> 
        <strong>0</strong> of <strong>16</strong> records processed 
       </small>     
      </td> 
      <td class="nowrap align_right">Yesterday at 8:06 AM</td> 
      <td class="nowrap">Tina Tester</td> 
     </tr> 

我需要驗證頁面上是否存在特定的表中,只是$ {}的BaseURL /status_submitted.png單元格或xpath位置。我該怎麼做呢?

+1

我們能看到該圖片的HTML? – Goralight

+0

是的,添加到問題中。 – pgtips

回答

1

給出示例文檔,這對我來說只是一個非常直接的優點,只不過是使用Google Chrome本身。將示例的內容放在一個帶有HTML/Body標籤的文件中,然後使用右鍵單擊檢查來檢查控制檯中的元素。再次右鍵單擊源標籤並選擇複製> Xpath。

這將導致以下xPath://*[@id="mass_list"]/tbody/tr[2]/td[1]/img其中第一個數字tr[2]是行,第二個數字td[1]是列。

第二種方法是基於與src屬性的圖像的文件路徑位置看圖像標籤本身和過濾://img[contains(@src, "status_submitted.png")]

+0

你能更具體嗎?如果我嘗試頁面應該包含xpath = ..,這不驗證圖像位於xpath。如果我嘗試使用Element Contain,提供xpath作爲定位器,並將src屬性作爲期望值,那麼我會收到錯誤,因爲它正在查找文本。你的意思是什麼關鍵詞? – pgtips

+0

@quietgrit元素應該可見 – Todor

+0

@Todor,不起作用,因爲該xpath上總是有一個圖像,但它需要成爲測試通過的特定圖像。 – pgtips

相關問題