QTP-createobject方法不完全总结
上一篇 /
下一篇 2011-07-26 17:53:19
/ 个人分类:QTP/UFT
*运行IE,并使ie最大化
,oai`)x0b~IT-qn7x0其他的word、excel、outlook就不赘述了51Testing软件测试网@"y9}"U
I
Set IE=CreateObject("internetExplorer.application")
/F!r,]lf?~0H0ie.AddressBar=False51Testing软件测试网U}'a
^l]w%V%Pzk g
ie.Visible=True51Testing软件测试网oW-p'_*W,gM[4O
ie.FullScreen=false51Testing软件测试网#F h-q*Y+Wl0q9o
ie.Navigate "www.baidu.com"51Testing软件测试网p(d2}
R}a
hwndie=ie.HWND
cq4V J7Q,_g5S0windows("hwnd:="& hwndie).maxmize
*利用dictionary传值
-N#ujs6hIcWJ0Dim arrcol
!}[z.RXs7|LX0Set dict=CreateObject("scripting.Dictionary")51Testing软件测试网 O"]WuZ
K?H#w\
dict.RemoveAll51Testing软件测试网hwP4xv8oQ|
dict.Add "no1","beijing"51Testing软件测试网eb-z-QI!g0I3h9T
dict.Add "no2","guangzhou"
0T[u/g6^+wp!Dm0arrcol=dict.Keys
L;U/A Dh+ez:_{o0For i=0 To UBound(arrcol)
)_f
QVI:zKHz0MsgBox arrcol(i)51Testing软件测试网v!tV x}n%Cz1C,j
Q-X D
msgbox dict.Item(arrcol(i))
q+t#a#Z v DN0Next
*操作txt文件
K r4KM0S(BC|8Ht0Dim fso51Testing软件测试网%y,Hl%z
{
A!dj8q$f
Set fso = CreateObject("Scripting.FileSystemObject")51Testing软件测试网!n$_]A Y$^
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
jaW-la1Z'o0MyFile.WriteLine("This is a test.")
o1_;J^&m%[)o%@8q4Hi0MyFile.Close
*wscript.shell运行txt,输入文字保存,关闭
-vnm,C y2J/l.o V@0Set wshshell=CreateObject("wscript.shell")
q![_,r6SS`0wshshell.Run "notepad"
Mh~abi8~2e0WScript.Sleep 500
+z+N5^U*} j%u k?0wshshell.AppActivate "notepad"51Testing软件测试网J*L_ wj D9M
wshshell.SendKeys "121212"
!cd~3k5eW0wshshell.SendKeys "^s"51Testing软件测试网!DOx/q
KK
wshshell.SendKeys "12222"
Xg#U
OX
U0wshshell.SendKeys "{TAB}"51Testing软件测试网w G'KL`z?
wshshell.SendKeys "{TAB}"51Testing软件测试网"E@d^{?S
wshshell.SendKeys "{ENTER}"51Testing软件测试网!v)o+ZXgE#q*E
wshshell.SendKeys "%{F4}"
*操作xml文件,循环获得title元素包含的文本节点的值
pt&w*}lN W JP*nZ0Set xmldoc=CreateObject("microsoft.xmldom")
4@&IM~1R0xmldoc.load ("D:\test.xml")
Y$Xts9v'e1d0Set x=xmldoc.getElementsByTagName("title")
q`q G$O,c0c:YT0For i=0 To x.length51Testing软件测试网BEL-])a
xq+DL!e
MsgBox x(i).childNodes(0).nodevalue51Testing软件测试网 M2~0LJv
next
*操作weidows剪贴板51Testing软件测试网f6lx:_:M7x
Set Clipboard = CreateObject("Mercury.Clipboard")
yNg\c4s3y;r0Clipboard.Clear
xh7eqb9\4ol8WO0ClipBoard.SetText “text”
F)Uc gnl&sJic
i r0Msgbox ClipBoard. GetText51Testing软件测试网0O,AXk~m
Set Clipboard=Nothing
51Testing软件测试网)PxKr0^2p
*模拟鼠标和键盘动作51Testing软件测试网A'Hy)k%?$Y3k
Set deviceReplay = CreateObject( "Mercury.DeviceReplay" )51Testing软件测试网PDX;^LLn
SystemUtil.Run "notepad.exe", "", "", "open"51Testing软件测试网,`0] _|bA:S
Window( "nativeclass:=Notepad", "index:=0" ).Activate micLeftBtn51Testing软件测试网 x5x5o'n%CP4I
deviceReplay.SendString( "DeviceReplay" )51Testing软件测试网;A$G8dBC]
Set deviceReplay = Nothing
收藏
举报
TAG: