Ruby 黄瓜+;Selenium-如何计算表中的行数?
有人知道使用Ruby、Cucumber和Selenium快速计算表中条目数的方法吗 该表相当基本,我想计算行数:Ruby 黄瓜+;Selenium-如何计算表中的行数?,ruby,selenium,cucumber,Ruby,Selenium,Cucumber,有人知道使用Ruby、Cucumber和Selenium快速计算表中条目数的方法吗 该表相当基本,我想计算行数: <table id="product_container"> <tr> <th>Product Name</th> <th>Qty In Stock</th> </tr> <tr> <td>...</td> <td>...&
<table id="product_container">
<tr>
<th>Product Name</th>
<th>Qty In Stock</th>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
</table>
品名
库存量
...
...
以下步骤定义应适用于水豚
Then /^I should have (\d+) table rows$/ do |number_of_rows|
actual_number = page.all('#product_container tr').size
actual_order.should == number_of_rows
end
用法:
Then I should have 10 table rows
.您可以使用:
page.should have_css "#product_container tr", :count => number_of_rows.to_i
我总是在这种情况下使用(硒法),效果很好:)在PHP中: $rowscont=$this->getXpathCount(//table[@id='product\u container']]/tr); 如果不想计算标题行数,则应将该表编辑为:
<table id="product_container">
<thead>
<tr>
<th>Product Name</th>
<th>Qty In Stock</th>
</tr>
</thead>
<tbody>
<tr>
<td>...</td>
<td>...</td>
</tr>
</tbody>
</table>
品名
库存量
...
...
然后您可以获得产品计数:
$rowsCount = $this->getXpathCount("//table[@id='product_container']/tbody/tr");
$rowscont=$this->getXpathCount(//table[@id='product\u container']]/tbody/tr);
$rowsCount = $this->getXpathCount("//table[@id='product_container']/tbody/tr");