You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在testRigor中抓取网页表格指定单元格值

用testRigor抓取表格Total行You Owe列数值的解决方案

页面包含2个表格,目标表格的HTML代码如下,需要抓取Total行You Owe列的数值。之前尝试的命令 grab value from row "Total" and column "You Owe" and save it as "amountOwed" 无法正确抓取或执行失败。

<table cellpadding="0" cellspacing="0" class="dataTable claimsTable table-rwd tablesaw-stack-collapse tablesaw-stack"
    data-tablesaw-mode="stack" id="table-8305">
    <thead>
        <tr>
            <th>Description/Code (CPT)</th>
            <th>Charge</th>
            <th scope="col">Discount</th>
            <th scope="col">Plan Savings</th>
            <th scope="col">Plan Paid</th>
            <th scope="col">You Owe</th>
        </tr>
    </thead>
    <tbody>

        <tr>
            <td>
                <b class="tablesaw-cell-label">Description/Code (CPT)</b>
                <span class="tablesaw-cell-content">
                    <span class="costDescription">Home Medical Equipment (Rental) (25820)</span>
                    <span class="tablesaw-stack-collapse-more" role="button">Show details</span>
                </span>
            </td>
            <td><b class="tablesaw-cell-label">Charge</b><span class="tablesaw-cell-content">$11.81</span></td>
            <td><b class="tablesaw-cell-label">Discount</b><span class="tablesaw-cell-content">$1.14</span></td>
            <td><b class="tablesaw-cell-label">Plan Savings</b><span class="tablesaw-cell-content">$0.00</span></td>
            <td><b class="tablesaw-cell-label">Plan Paid</b><span class="tablesaw-cell-content">$0.00</span></td>
            <td><b class="tablesaw-cell-label">You Owe</b><span class="tablesaw-cell-content">$0.00</span></td>
        </tr>

        <tr>
            <td>
                <b class="tablesaw-cell-label">Description/Code (CPT)</b>
                <span class="tablesaw-cell-content">
                    <span class="costDescription">Drugs (25370)</span>
                    <span class="tablesaw-stack-collapse-more" role="button">Show details</span>
                </span>
            </td>
            <td><b class="tablesaw-cell-label">Charge</b><span class="tablesaw-cell-content">$8,625.81</span></td>
            <td><b class="tablesaw-cell-label">Discount</b><span class="tablesaw-cell-content">$669.51</span></td>
            <td><b class="tablesaw-cell-label">Plan Savings</b><span class="tablesaw-cell-content">$1,169.18</span></td>
            <td><b class="tablesaw-cell-label">Plan Paid</b><span class="tablesaw-cell-content">$5,048.51</span></td>
            <td><b class="tablesaw-cell-label">You Owe</b><span class="tablesaw-cell-content">$1,069.10</span></td>
        </tr>

        <tr>
            <td>
                <b class="tablesaw-cell-label">Description/Code (CPT)</b><span class="tablesaw-cell-content">
                <span class="costDescription">Hearing (87271)</span>
                    <span class="tablesaw-stack-collapse-more" role="button">Show details</span>
                </span>
            </td>
            <td><b class="tablesaw-cell-label">Charge</b><span class="tablesaw-cell-content">$1,194.10</span></td>
            <td><b class="tablesaw-cell-label">Discount</b><span class="tablesaw-cell-content">$204.22</span></td>
            <td><b class="tablesaw-cell-label">Plan Savings</b><span class="tablesaw-cell-content">$16.37</span></td>
            <td><b class="tablesaw-cell-label">Plan Paid</b><span class="tablesaw-cell-content">$0.00</span></td>
            <td><b class="tablesaw-cell-label">You Owe</b><span class="tablesaw-cell-content">$0.00</span></td>
        </tr>

    </tbody>
    <tfoot>
        <tr>
            <td>
                <b class="tablesaw-cell-label">Description/Code (CPT)</b>
                <span class="tablesaw-cell-content">Total</span>
            </td>
            <td><b class="tablesaw-cell-label">Charge</b><span class="tablesaw-cell-content">$9,831.72</span></td>
            <td><b class="tablesaw-cell-label">Discount</b><span class="tablesaw-cell-content">$874.87</span></td>
            <td><b class="tablesaw-cell-label">Plan Savings</b><span class="tablesaw-cell-content">$1,185.55</span></td>
            <td><b class="tablesaw-cell-label">Plan Paid</b><span class="tablesaw-cell-content">$5,048.51</span></td>
            <td><b class="tablesaw-cell-label">You Owe</b><span class="tablesaw-cell-content">$1,069.10</span></td>
        </tr>
    </tfoot>
</table>

可行的testRigor命令方案

目标表格是响应式堆叠表格(tablesaw-stack类),移动端视图下单元格垂直堆叠,默认行/列识别逻辑失效,需指定表格唯一标识或用精准定位:

  1. 指定表格ID定位

    grab value from row "Total" in table with id "table-8305" and column "You Owe" and save it as "amountOwed"
    
  2. 结合表格类和内容定位

    grab text from element containing "You Owe" that is in row containing "Total" in table with class "claimsTable" and save it as "amountOwed"
    
  3. XPath精准定位
    直接定位tfoot中的目标单元格内容:

    grab value from xpath "//table[@id='table-8305']/tfoot/tr/td[contains(.,'You Owe')]/span[@class='tablesaw-cell-content']" and save it as "amountOwed"
    

内容的提问来源于stack exchange,提问作者Aman Ranu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 04:27:34