qtp 模拟google查询
Option ExplicitSub testGoogle
Dim obj1,obj2,counts,i,txt,lens,lenss,tlen
Set obj1 = Description.Create()
obj1("class").value="l"
SystemUtil.CloseProcessByName("iexplore.exe")
SystemUtil.Run "iexplore.exe","http://www.google.cn"
With Browser("MicClass:=Browser").Page("MicClass:=Page")
.WebEdit("name:=q").Set "php"
.WebButton("name:=Google 搜索").click
wait(2)
set obj2 =.ChildObjects(obj1)
counts = obj2.count
For i=0 to counts-1
txt=obj2(i).GetROProperty("innertext")
lens=Instr(txt,"php")
lenss=instr(txt,"PHP")
tlen=lens+lenss
If tlen=0 Then
print "没有发现关键字"
End If
Next
End with
End Sub 1、SystemUtil.CloseProcessByName("iexplore.exe")
2、SystemUtil.Run "iexplore.exe","http://www.google.cn"
3、childobjects ::shanguang::: 是可以实现什么功能的。不错不错,看看。 WebEdit("name:=q")这个对象只的是输入框嘛?
qtp和 google继续
冒个泡,写点东西,希望能够有用Option Explicit
Sub testGoogle
Dim obj1,obj2,counts,i,txt,lens,lenss,tlen
Set obj1 = Description.Create()
obj1("class").value="l"
wait(2)
With Browser("MicClass:=Browser").Page("MicClass:=Page")
wait(2)
set obj2 =.ChildObjects(obj1)
counts = obj2.count
For i=0 to counts-1
txt=obj2(i).GetROProperty("innertext")
lens=Instr(txt,"php")
lenss=instr(txt,"PHP")
tlen=lens+lenss
If tlen=0 Then
reporter.ReportEvent micFail,"cann't find the word","cann't find the word"
End If
Next
End with
End Sub
Sub main()
Dim pagecount
SystemUtil.CloseProcessByName("iexplore.exe")
SystemUtil.Run "iexplore.exe","http://www.google.cn"
wait(2)
With Browser("MicClass:=Browser").Page("MicClass:=Page")
pagecount=0
.WebEdit("name:=q").Set "php"
.WebButton("name:=Google 搜索").click
Do while true
pagecount=pagecount+1
If pagecount =1 Then
Call testGoogle
else
If .Link("text:="&pagecount,"html tag:=A").Exist(2) Then
.Link("text:="&pagecount,"html tag:=A").click
wait(2)'等待页面刷新,可以设置同步点
Call testGoogle
else
Exit do
End If
End If
Loop
End with
SystemUtil.CloseProcessByName("iexplore.exe")
End Sub
Call main() :) :) :)
页:
[1]