【问题标题】:How to access the table,tr,td which has no attributes using Watir如何使用 Watir 访问没有属性的表、tr、td
【发布时间】:2015-06-30 20:12:51
【问题描述】:

我正在尝试访问表格以及它的行和表格数据(td),通常表格、tr 和 td 没有可使用的属性我尝试使用索引但仍然没有用,即使我尝试使用的父元素表我仍然无法访问它。

<div class = "Links"></div>
<div class = "board">
<table>
<tbody>
<tr><td>Name</td><td>Value</td></tr>
<tr><td>shaik</td><td>500</td></tr>
<tr><td>shahrukh</td>900<td><span style="" has css properties ></span></td></tr>
</tbody>
</table>
</div>

我尝试了以下方式

@ie.table(index,0) and 
@ie.div(:class,'Links').table(:index,0)

由于无法定位元素而返回错误

【问题讨论】:

  • 您是否确认该表不在frameiframe 中?我记得您之前的一些问题是由框架引起的。
  • @Justin Ko 框架/iframes 根本没有使用。
  • 我认为您需要提供有关如何重现问题的更多详细信息。我使用您提供的 HTML 创建了一个页面,@ie.table(index,0) 按预期工作。
  • 即使我尝试了与上面相同的语法,让我检查一次......

标签: ruby watir watir-webdriver


【解决方案1】:

@ie.table 本身应该可以工作。 @ie.div(:class, 'Links') 不是 table 元素的父元素,因为 &lt;/div&gt; 在 dom 中位于 &lt;table&gt; 之前。

【讨论】:

  • irb(main):034:0> @ie.table(:index, 0) => #<:table:0x4edb24c located="false" how=":index" what="0"> ,I当我尝试使用时出现上述错误。
【解决方案2】:

试试这个,

myelem = browser.tr(:text, /Name/).td(:index => 2).text
 #or you can use the more user-friendly aliases for those tags
myelem = browser.row(:text, /Name/).cell(:index => 2).text

【讨论】:

  • irb(main):005:0> @ie.tr(:text,'name').td(:index,2).text NoMethodError: undefined method `tr' for #
  • irb(main):007:0> @ie.browser.tr(:text,'STORENO').td(:index,2).text NoMethodError: undefined method `browser' for # <:ie:0x4ef93a0>
  • irb(main):008:0> browser.tr(:text,'name').td(:index,2).text NameError: undefined local variable or method `browser' for # 来自 (irb):8
  • 这实际上适用于 Watir::Browser 类你能从 Watir::IE 类中获取该对象吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 2017-05-28
  • 1970-01-01
相关资源
最近更新 更多