无法使用Selenium java找到动态搜索结果

时间:2018-01-19 09:15:38

标签: java selenium automation

我正在尝试使用搜索值验证搜索结果。这是一个显示所有现有关键字的表格。当需要列出特定关键字时,用户可以搜索关键字。搜索结果显示在搜索之前列出所有关键字的同一个表格中。

特别是当我搜索关键字android," android标题"和" android"关键字显示在表格主体中。我使用xpath获取了这两个元素的位置并在控制台中打印。但是在控制台中它显示为"描述"和" Oppo"显示在第1行和第2行,其中列出了所有关键字。

下面是HTML代码。

<div id="keyword-grid" class="grid-view">
   <table class="items table table-striped">
      <thead>
         <tr>
            <th id="keyword-grid_c0"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=name">Name<span class="caret"></span></a></th>
            <th id="keyword-grid_c1"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=behaviour">Behaviour<span class="caret"></span></a></th>
            <th id="keyword-grid_c2"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=status">Status<span class="caret"></span></a></th>
            <th id="keyword-grid_c3"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=createdAt">Created At<span class="caret"></span></a></th>
            <th id="keyword-grid_c4"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=createdBy">Created By<span class="caret"></span></a></th>
            <th class="button-column" id="keyword-grid_c5">&nbsp;</th>
         </tr>
      </thead>
      <tbody>
         <tr class="odd">
            <td>Description</td>
            <td>Manual</td>
            <td><span class="badge badge-success">Active</span></td>
            <td>2018-01-16 05:48:02</td>
            <td>Admin</td>
            <td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/163"><i class="icon-eye-open"></i></a>  </td>

         <tr class="odd">
            <td>Oppo</td>
            <td>Manual</td>
            <td><span class="badge badge-success">Active</span></td>
            <td>2017-11-16 06:32:19</td>
            <td>Digitalbox Testing</td>
            <td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/161"><i class="icon-eye-open"></i></a>  </td>
         </tr>
         <tr class="even">
            <td>android headlines</td>
            <td>Manual</td>
            <td><span class="badge badge-success">Active</span></td>
            <td>2017-11-15 07:53:02</td>
            <td>Admin</td>
            <td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/160"><i class="icon-eye-open"></i></a>  </td>
         </tr>
         <tr class="odd">
            <td>api</td>
            <td>Manual</td>
            <td><span class="badge badge-success">Active</span></td>
            <td>2017-11-15 07:53:02</td>
            <td>Admin</td>
            <td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/159"><i class="icon-eye-open"></i></a>  </td>
         </tr>
         <tr class="even">
            <td>android</td>
            <td>Manual</td>
            <td><span class="badge badge-important">Deleted</span></td>
            <td>2017-11-09 09:43:50</td>
            <td>Admin</td>
            <td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/158"><i class="icon-eye-open"></i></a>  </td>
         </tr>
      </tbody>
   </table>
</div>

这是我试图获取搜索结果的代码。

driver1.findElement(By.xpath("//*[@id=\"keyword-grid\"]/table/tbody/tr[1]"));
driver1.findElement(By.xpath("//*[@id=\"keyword-grid\"]/table/tbody/tr[2]"));
System.out.print(driver1.findElement(By.xpath("//*[@id=\"keyword-grid\"]/table/tbody/tr[1]")).getText());
System.out.print(driver1.findElement(By.xpath( "//*[@id=\"keyword-grid\"]/table/tbody/tr[2]")).getText());

如何打印android搜索结果?

0 个答案:

没有答案