QTP 常用函数
上一篇 / 下一篇 2008-01-29 22:13:51 / 个人分类:—— QuickTest Pro
1.GetCellData函数 51Testing软件测试网 ? |,DO rD9Yrf,|:x
51Testing软件测试网K*~n4wQ4[YC\作用:获取单元格的值51Testing软件测试网`$~#sN*? E/^` D`
51Testing软件测试网AQ wR]kj9D4|E 例: rowCount = Browser("xxx ").Page("xxx ").Frame("xxx").WebTable("xxx").RowCount51Testing软件测试网5zwj8Quj.F!C
For counter = 1 To rowCount51Testing软件测试网E#r1aW` {4B
text = Browser("xxx").Page("xxx").Frame("xxx").WebTable("xxx").GetCellData(counter,1)
7Xu y } Z O&g0 If (text = "xxx") Then
c{)g}z-{'h KC0 counter = counter - 1
OzFR.Y/u0 selectNO = "#" & counter51Testing软件测试网PV9lo!I(B
@ }
Browser("xxx").Page("xxx").Frame("xxx").WebRadioGroup("xxx").Select selectNO51Testing软件测试网^0A'J:S*k,m
Exit For51Testing软件测试网R'Zaw%@%m9Y$z
End If
S^5V-Qbj&[8O H0Next51Testing软件测试网1x,g&H:q7Zsh
0nowu ABE02.把值插入datatable里
-tZSRO!N051Testing软件测试网,m gOPf 例: datatable.setcurrentrow(i)51Testing软件测试网7q/v6Pk;A l'tS-sK1S
datatable.value("name","Global")="name"
/A2gJs'uJ/s$U0 datatable.value("passwd","Global")="passwd"
3.用代码来启动浏览器51Testing软件测试网m6Rs[4?T:@
51Testing软件测试网[7e-T(^J@ Browser1 = "IE"
zY:t,G.f`q#f6w0 StartURL = "www.51testing.com"51Testing软件测试网Sd6j_}Hc
IF Browser1 = "IE" THEN51Testing软件测试网/F/R7}
}(I
}a
set IE = CreateObject("InternetExplorer.Application")
#j*J+MPho)A0 IE.Visible = true
'Hh$d1B%X:`
]b n0 IE.Navigate StartURL51Testing软件测试网Qhh!Zq6Lh)JX
END IF51Testing软件测试网8B+f$\*je0PJ|S
51Testing软件测试网qX|I&X9a5YaS
6q5O'j5o-q_04.ExecuteFile函数51Testing软件测试网 d e\7P,u'd3Le/X3U ?z:H
$w6vC{w&D8C0 作用:ExecuteFile 可以直接执行vbs文件,而不需要将其导入resource中 51Testing软件测试网h [0Q!A5N6n"b
ExecuteFile FileName
M:up(E)L0 说明:where FileName is the absolute or relative path of your VBscrīpt file.51Testing软件测试网"gn+[;CN/ARU*N
例:ExecuteFile("F:\test.vbs")
4w~w*K"fPP051Testing软件测试网f;]B3Y-Z5.Strcomp函数 51Testing软件测试网R3OUn-S!_ j5|-e_'j
:T%Ep&i2m[[?V0 作用:比较文本51Testing软件测试网 ne#B]@W:N
51Testing软件测试网1S:]Np*`m"l ?6Z 例:dim strtext1,strtext2,str ,str1,comp1
8R1}s Oa1V.z0 strtext1 = "xxx"
`B;Pf)D3k0 strtext2 = "xxx"51Testing软件测试网@2s2}Kg3A&`BJO"u
str = VbWindow("xxx").VbWindow("xxx").VbLabe1("xxx").GetTOProperty("text")51Testing软件测试网O9cB1q$UQA:h5Ve
str1= VbWindow("xxx").VbWindow("xxx").VbLabel("xxx").GetTOProperty("text")51Testing软件测试网"I#D dH!`2P9y
comp1=strcomp(strtext1,str,0)51Testing软件测试网}%q:uc@g"s*b
If comp=0 Then
_x$ha9A w
k*]P0 msgbox “这两个串相等”51Testing软件测试网$i'FD"b!fL(In
else51Testing软件测试网&^j7S
t:d#v
msgbox str
jcUb
U0B-s0 End If
6.CaptureBitmap
@*d\D+gR6x:v;nq8FM0PQnj^5q9O-y6a0 作用:捕获屏幕51Testing软件测试网`}(PP5HQ
?"Q2n0z ?~:m}*H"]{Y,R07. GetROProperty51Testing软件测试网9R(bc:_5]g`
XCbm0DL:[I.~0 作用:取对象属性值
E4Vn"u)q NEZX051Testing软件测试网.W_Cp `?E例:VbWindow("xxx").VbWindow("xxx").VbWindow("xxx").ActiveX("xxx").GetROProperty("TextMatrix(1,0)") 51Testing软件测试网"}&K@'\6K%x"Vq
0Q*X0w8fCa08.ExitAction - 退出当前操作,无论其循环属性如何。51Testing软件测试网*_2j4lCr ^
ExitActionIteration - 退出操作的当前循环。
UR V%hK"g0 ExitRun - 退出测试,无论其循环属性如何。51Testing软件测试网:PV/q'wPl0Sg
ExitGlobalIteration - 退出当前全局循环。
51Testing软件测试网!e8S5GFg;i6Nr
9.如何使用Excel对象处理数据?51Testing软件测试网7fv5c([N
Dim xl
3V@_A_?SxIBL2R0 打开excel文件51Testing软件测试网%Y q0X
A6^#M{'ikf
Function OpenExcelFile(strFilePath)51Testing软件测试网_s4o6zFT
Set xl = CreateObject("Excel.Application")
O?#pC:M5N%O0 xl.Workbooks.Open strFilePath51Testing软件测试网!h.Y*Y!ZG
End Function51Testing软件测试网Z+\9i8i3K`,@
获得指定单元格数据
,~;]8J9Q5C'_a@2fL0 Function GetCellData(strSheet,rwIndex,colIndex)51Testing软件测试网gR$?-PB)eh;r
GetCellData = xl.WorkSheets(strSheet).Cells(rwIndex,colIndex)