You are the best one!!

watir中对table的操作

上一篇 / 下一篇  2008-06-23 16:14:06 / 个人分类:Ruby/Watir Space

在Watir中
对于实例化的$ie对象,我们可以通过以下的两种方式来访问他的Table元素:
t = $ie.table(:id,"data")
t = Table.new($ie,:id,"data")
同样,对于tr和td来说,分别也有以上两种方法:
tr = $ie.row(:id,"title")
tr = TableRow.new($ie,:id,"title")
td = $ie.cell(:id,"name")
td = TableCell.new($ie,:id,"name")
Watir中Table,TableBody,TableRow,TableCell这几个类,都提供了一个索引方法"[](index)"来定位其下一层的子元素对象,该方法为实例方法,"index"为传入的参数,索引值从1开始,而非从0开始。
用法如下:
以table的第一行,第一个元素为例:
tr1 = t.[](1)
td1 = tr1.[](1)
也可以连续访问:td1 = t.[](1).[](1)
如果td中还有其他元素,可以通过td的实例方法直接访问,以checkbox为例:
cb = td1.checkbox(:id,'navigate_id').click

对于以上所提到的对象,都是从Element继承而来,所以click,enabled?,exists?,fireEvent,flash,focus等方法都直接可以使用。
如果你的td元素定位准确了,且鼠标响应事件没有错误的话,那么应该能看到点击后的效果。
建议你先用flash方法定位一下要操作的元素。
建议多查一下Watir的API Referencehttp://wtr.rubyforge.org/rdoc/

我写的代码如下:

def logOut()
t=@ie.table(:id,"CoolMenu2menutable")
@td_logout=t.[](1).[](16)
end

先找到Table,再索引TR,再索引到TD

===================================================

t1 = t.[](1).[](1).to_s

puts t1  # print the cell of 1 row and 1 col

 

 


TAG:

 

评分:0

我来说两句

日历

« 2024-05-03  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 29256
  • 日志数: 35
  • 文件数: 2
  • 书签数: 2
  • 建立时间: 2008-06-07
  • 更新时间: 2014-08-04

RSS订阅

Open Toolbar