51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1938|回复: 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空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    难过
    2015-9-21 13:50
  • 签到天数: 4 天

    连续签到: 1 天

    [LV.2]测试排长

    2#
    发表于 2009-6-16 22:45:00 | 只看该作者
    1、SystemUtil.CloseProcessByName("iexplore.exe")
    2、SystemUtil.Run "iexplore.exe","http://www.google.cn"
    3、childobjects
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    3#
    发表于 2009-6-16 23:01:05 | 只看该作者
    ::shanguang::: 是可以实现什么功能的。不错不错,看看。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    4#
    发表于 2009-6-17 11:35:19 | 只看该作者
    WebEdit("name:=q")  这个对象只的是输入框嘛?
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    5#
     楼主| 发表于 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()
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2016-5-18 09:09
  • 签到天数: 19 天

    连续签到: 1 天

    [LV.4]测试营长

    6#
    发表于 2009-6-17 11:51:05 | 只看该作者
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

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

    GMT+8, 2024-4-28 22:38 , Processed in 0.078772 second(s), 27 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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