QTP对网页表单处理

上一篇 / 下一篇  2012-07-06 15:07:59

1.如何遍历WebTable的所有单元格?

QTP中的WebTable测试对象提供了RowCountColumnCount,可用于遍历WebTable中的所有单元格。

再配合GetCellDataChildItem等,就可以对WebTable中的每一个单元格中的对象进行操作。

下面的例子获取到WebTable每一个单元格中的链接对象:

Set w_WebTable = Browser(XXX).Page(XXX).WebTable(XXX)
For I = 1 To w_WebTable.
RowCount
  For J =1 To w_WebTable.ColumnCount(1) 
'注意这块的写法是数字1,而不是字母“i”
     Set CellLink = w_WebTable.ChildItem(I, J, "Link" , 0 )
  Next
Next

2.使用GetRowWithCellText方法找到webtable中某一元素所在的行.

 : iRow=obj_table.GetRowWithCellText("helloWorld",1,1)

    意为:从表格第一行、第一列开始遍历,返回表格种helloWorld所在的行数,并将值付给iRow.

Call  CloseWeb()  '此函数意为在执行操作之前关闭所有浏览器窗口
systemutil.Run"iexplore.exe","
http://192.168.8.9:8000/xzfw/","","",3
Browser("电子政务").Page("电子政务").WebEdit("user_code").Set "admin"
Browser("电子政务").Page("电子政务").WebEdit("user_pass").SetSecure "49eaded9cd8e47be2ec7d372"
Browser("电子政务").Page("电子政务").Image("dl-9").Click
wait 6
Browser("电子政务").Page("::::行政审批系统::::").Link("日程安排").Click
Browser("电子政务").Page("::::行政审批系统::::").Frame("38").WebElement("新建安排").Click
 callUniqueID(a)'调用此函数意为产生一个唯一的值格式为:"安排041916548
"
Browser("电子政务").Page("::::行政审批系统::::").Frame("38_2").WebEdit("weedayPlan.title").Set ""&a
Browser("电子政务").Page("::::行政审批系统::::").Frame("38_2").WebEdit("weedayPlan.address").Set "shanghai pudong district"
Browser("电子政务").Page("::::行政审批系统::::").Frame("38_2").Image("calendar_o").Click
Browser("电子政务").Window("日期-时间选择--网页对话框").Page("日期-时间选择").WebElement("20").Click
Browser("电子政务").Window("日期-时间选择--网页对话框").Page("日期-时间选择").WebButton("选择").Click
Browser("电子政务").Page("::::行政审批系统::::").Frame("38_2").Image("calendar_o_2").Click
Browser("电子政务").Window("日期-时间选择--网页对话框").Page("日期-时间选择").WebElement("30").Click
Browser("电子政务").Window("日期-时间选择--网页对话框").Page("日期-时间选择").WebButton("选择").Click
Browser("电子政务").Page("::::行政审批系统::::").Frame("38_2").WebList("weedayPlan.importantType").Select "紧急"
Browser("电子政务").Page("::::行政审批系统::::").Frame("38_2").WebEdit("weedayPlan.content").Set "这是新建安排,务必严格执行,"
Browser("电子政务").Page("::::行政审批系统::::").Frame("38_2").WebButton("保存").Click
'new process begin
'Browser("电子政务").Page("::::行政审批系统::::").Frame("38").webtable("主题").click

Setobj_table=Browser("::::行政审批系统::::").Page("::::行政审批系统::::").Frame("38").WebTable("主题")
iRow=obj_table.GetRowWithCellText
(""&a,1,1)    
Set CellLink=obj_table.
ChildItem
(iRow,6,"Link",0)
 CellLink.click
Browser("::::行政审批系统::::").Dialog("Microsoft Internet Explorer").Activate
If  Browser("::::行政审批系统::::").Dialog("Microsoft Internet Explorer").Static("text:=确定要使当前安排失效吗?").Exist(1)Then
 Browser("::::行政审批系统::::").Dialog("Microsoft Internet Explorer").WinButton("确定").Click
 Reporter.ReportEvent micPass,"有效性验证","默认失效Ok,安排使失效!"
 elseReporter.ReportEvent micFail,"有效性验证","没有按默认取值,检查程序!"
End If
Setobj_table=Browser("::::行政审批系统::::").Page("::::行政审批系统::::").Frame("38").WebTable("主题")
iRow=obj_table.GetRowWithCellText
(""&a,1,1)    
Set CellLink=obj_table.
ChildItem
(iRow,6,"Link",0)
 CellLink.click
If  Browser("::::行政审批系统::::").Dialog("Microsoft Internet Explorer").Static("text:=确定要使当前安排生效吗?").Exist(1)
Then
 Browser("::::行政审批系统::::").Dialog("Microsoft Internet Explorer").WinButton("确定").Click
 Reporter.ReportEvent micPass,"有效性验证","安排使生效OK!"
 elseReporter.ReportEvent micFail,"有效性验证","没有按默认取值,检查程序!"
End If


TAG: QTP 表单

 

评分:0

我来说两句

Open Toolbar