【问题标题】:Check Style Table with watir用 watir 检查样式表
【发布时间】: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 =&gt; 'content-global-box').table.tbody.tr 返回类属性为 'content-global-box' 的 div 中第一个表的第一行。该行是空的:&lt;tr&gt;&lt;/tr&gt;
  • 那么我应该做的是:browser.div(:class=> 'content-global-box').table.tbody.tr[1] ?
  • 这将返回一个包含 4 个表格的表格单元格。像这样的东西应该打印每个表的.style属性,其类属性为'content-global-box':b.div(:class =&gt; 'content-global-box').tables(:class=&gt;"blocos").each { |table| puts table.style}

标签: css html-table each watir


【解决方案1】:

我可能误解了这个问题,但这将打印每个表的 .style 值,每个表包含一个“blocos”类,每个 div 中包含一个“content-global-box”类:

b.divs(:class => 'content-global-box').each do |div|
  div.tables(:class=>"blocos").each do |table|
    puts table.style
  end
end

【讨论】:

  • .style 将返回属性值 - 例如“background:#f2f2f2;opacity:0.7;border:1px solid #eee;cursor:default;”。如果目标是检查不透明度,也许.style('opacity') 会很有用。它具有获取计算样式以及节省样式属性的手动解析的好处。
  • @Justin Ko:+1。我错过了这个要求。这是.style 方法文档的链接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多