【发布时间】:2014-10-27 10:58:18
【问题描述】:
我在提取样式表以通过 .style 方法使用 watir 时遇到问题
我在网络中有这样的结构:
.
.
.
<div class="content-global-div">
<table class="content-global-table content-global-bg">
<tbody>
<tr>
<td style="vertical-aling:top;padding:25px 40px;">
<div class="content-global-title">...</div>
<div class="content-global-title">...</div>
<div class="content-global-box">
<div style="...">...</div>
<table cellspacing="0">
<tbody>
<tr></tr>
<tr>
<td style="padding:10px;">
<table class="blocos" style="background:#f2f2f2;opacity:0.7;border:1px solid #eee;cursor:default;"></table>
<table class="blocos" style="background:#f2f2f2;opacity:0.7;border:1px solid #eee;cursor:default;"></table>
<table class="blocos" style=""></table>
<table class="blocos" style=""></table>
.
.
.
</td>
</tr>
</tbody>
</table>
</div>
<div class="content-global-box">
<div style="...">...</div>
<table cellspacing="0">
<tbody>
<tr></tr>
<tr>
<td style="padding:10px;">
<table class="blocos" style="background:#f2f2f2;opacity:0.7;border:1px solid #eee;cursor:default;"></table>
<table class="blocos" style="background:#f2f2f2;opacity:0.7;border:1px solid #eee;cursor:default;"></table>
<table class="blocos" style=""></table>
<table class="blocos" style=""></table>
.
.
.
</td>
</tr>
</tbody>
</table>
</div>
<div class="content-global-box">
<div style="...">...</div>
<table cellspacing="0">
<tbody>
<tr></tr>
<tr>
<td style="padding:10px;">
<table class="blocos" style="background:#f2f2f2;opacity:0.7;border:1px solid #eee;cursor:default;"></table>
<table class="blocos" style="background:#f2f2f2;opacity:0.7;border:1px solid #eee;cursor:default;"></table>
<table class="blocos" style=""></table>
<table class="blocos" style=""></table>
.
.
.
</td>
</tr>
</tbody>
</table>
</div>
.
.
.
我需要做的是将自己放在每个类表中:blocos 并专门可视化不透明度样式,现在我拥有的是以下内容:
tbl = browser.div(:class => 'content-global-box').table.tbody.tr
tbl.tds.each do |td|
puts td.style.to_s()
end
但没有给我结果,我不确定这就是我 需要, 有人可以这么好心解释怎么做吗?
【问题讨论】:
-
browser.div(:class => 'content-global-box').table.tbody.tr返回类属性为 'content-global-box' 的 div 中第一个表的第一行。该行是空的:<tr></tr> -
那么我应该做的是:browser.div(:class=> 'content-global-box').table.tbody.tr[1] ?
-
这将返回一个包含 4 个表格的表格单元格。像这样的东西应该打印每个表的
.style属性,其类属性为'content-global-box':b.div(:class => 'content-global-box').tables(:class=>"blocos").each { |table| puts table.style}
标签: css html-table each watir