如何使用Robot Framework验证特定元素中是否存在图像

时间:2017-03-01 17:01:42

标签: automation robotframework

我正在尝试验证特定元素中网页上是否存在特定图像。图片:

  • 没有唯一ID
  • 没有唯一的alt
  • src属性包含我试图忽略的查询字符串
  • 在页面上多次出现

我无法使用Page Should Contain Image,因为它出现多次,但我需要验证它是否出现在特定的表格单元格中。图像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>

我需要验证在特定表格单元格或xpath位置内的页面上是否存在$ {BaseUrl} /status_submitted.png。我该怎么做?

1 个答案:

答案 0 :(得分:1)

鉴于示例文档,对我来说这是一个相当直接的例外,只使用谷歌Chrome本身。将示例的内容放在一个带有HTML / Body标签的文件中,然后使用右键单击inspect来检查控制台中的元素。再次右键单击源标记,然后选择复制&gt; Xpath。

这将产生以下xPath://*[@id="mass_list"]/tbody/tr[2]/td[1]/img,其中第一个数字tr[2]是行,第二个数字td[1]是列。

第二种方法是查看图像标记本身并根据具有该src属性的图像的文件路径位置进行过滤://img[contains(@src, "status_submitted.png")]

相关问题