51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1968|回复: 5
打印 上一主题 下一主题

[原创] qtp 模拟google查询

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2009-6-16 18:41:27 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
Option Explicit
Sub 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
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2009-6-17 11:49:00 | 显示全部楼层

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 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-24 06:25 , Processed in 0.069704 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表