如何基于一行中的文本单击表中的链接 [英] how to click a link in a table based on the text in a row

查看:72
本文介绍了如何基于一行中的文本单击表中的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用页面对象和watir-webdriver,如何基于以下行文本单击表中的链接:

Using page-object and watir-webdriver how can I click a link in a table, based on the row text as below:

该表包含3行,在第一列中具有名称,在右侧的列中具有对应的详细信息"链接:

The table contains 3 rows which have names in the first column, and a corresponding Details link in columns to the right:

仪表板....详细信息

DASHBOARD .... Details

示例....详细信息

以此类推.

<div class="basicGridHeader">
    <table class="basicGridTable">ALL THE DETAILS: 
    ....soon
    </table>

</div>

<div class="basicGridWrapper">
    <table class="basicGridTable">
        <tbody id="bicFac9" class="ide043">
            <tr id="id056">
                <td class="bicRowFac10">
                    <span>
                        <label class="bicDeco5">
                            <b>DASHBOARD:</b> ---> Based on this text
                        </label>
                    </span>
                </td>

                <td class="bicRowFac11">
                    ....some element
                </td>

                <td class="bicRowFac12">
                    <span>
                        <a class="bicFacDet5">Details</a> ---> I should able click this link
                    </span>
                </td>
            </tr>
        </tbody>
    </table>
</div>

推荐答案

您可以找到包含指定文本的单元格,转到父行,然后在该行中找到详细信息链接.

You could locate a cell that contains the specified text, go to the parent row and then find the details link in that row.

假设您可能要单击其他详细信息链接,我将定义一个view_details方法,该方法接受要查找的行的文本:

Assuming that there might be other detail links you would want to click, I would define a view_details method that accepts the text of the row you want to locate:

class MyPage
  include PageObject

  table(:grid){ div_element(:class => 'basicGridWrapper')
    .table_element(:class => 'basicGridTable') }

  def view_details(label)
    grid_element.cell_element(:text => /#{label}/)
      .parent
      .link_element(:text => 'Details')
      .click
  end

end

然后您可以点击以下链接:

You can then click the link with:

page.view_details('DASHBOARD')

这篇关于如何基于一行中的文本单击表中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆