【发布时间】:2015-11-06 12:59:27
【问题描述】:
我正在使用 Watir 和 Phantomjs 在自助门户上管理客户设置。
我正在处理一个包含单个列和几行的表,其中显示了可以订阅的可用包的列表。在每一行我都可以找到描述和一个按钮。每个按钮都有自己的页面生成的 ID,但所有按钮都有相同的描述。 粘贴格式化的 HTML 我发现
+-----------------------------------+
| Available Packages |
+-----------------------------------+
| Package_1 [subscribe] |
| Package_2 [subscribe] |
| Package_3 [subscribe] |
| Package_4 [subscribe] |
| Package_5 [subscribe] |
我正在尝试单击包含文本但未成功的特定行的按钮。我什至无法选择行...我该怎么做?
browser.td(:text => /^Package_2/)
返回
=> #<Watir::TableDataCell:0x..fc0259e6592e39a6 located=false selector={:text=>/^Package_2/, :tag_name=>"td"}>
HTML 表格是在加载页面上生成的。一个有两个包的例子是:
<table id="j_id174" class="scrollTable4" width="820px">
<thead class="fixedHeader4 headerFormat4">
<tr>
<td style="background:none"></td>
<td width="100%"></td>
</tr>
</thead>
<tbody class="scrollContent4 bodyFormat4">
<tr id="showdivj_id1740" style="background-color:#e0e0e0;">
<td style="background-color:#ffffff;background-image:none;"><a href="javascript:DivStatus( 'mondiv','j_id174',0)" style="text-decoration:none;"><img id="imgj_id1740" border="0" src="../imgs/puce_plus.png" width="13" height="13"></a></td>
<td>
<div style="position:relative;"><span class="xdt">PACKAGE_1</span><button type="button" onclick="return _chain('blockpage()','submitForm(\\'j_id13\\',0,{source:\\'j_id174:0:j_id180\\'});return false;',this,event,true)" class="xe4 x7i">subscribe</button></div>
</td>
</tr>
<tr id="showdivj_id1741" style="background-color:#e0e0e0;">
<td style="background-color:#ffffff;background-image:none;"><a href="javascript:DivStatus( 'mondiv','j_id174',1)" style="text-decoration:none;"><img id="imgj_id1741" border="0" src="../imgs/puce_plus.png" width="13" height="13"></a></td>
<td>
<div style="position:relative;"><span class="xdt">PACKAGE_2</span><button type="button" onclick="return _chain('blockpage()','submitForm(\\'j_id13\\',0,{source:\\'j_id174:1:j_id180\\'});return false;',this,event,true)" class="xe4 x7i">subscribe</button></div>
</td>
</tr>
</tbody>
</table>
非常感谢!
【问题讨论】:
-
那么至少点击任何一行行得通吗?请edit您的问题进一步澄清并添加表格的标记。您可能需要使用 XPath 表达式或在 DOM 中从一个元素移动到下一个元素。无论哪种方式,我们都需要查看标记。
标签: ruby-on-rails phantomjs watir