fireevent在QTP的应用,丰富了控件的行为。

来源:互联网 发布:洪城网络 编辑:程序博客网 时间:2024/05/29 11:21

--内容出自网友 zte-boy

 

'脚本经过自己稍加修改运行是没有问题的。并且很好用~

FireEvent函数可以实现有些控件的一些特殊的行为要求,比如onchange, onclick, ondblclick, onblur, onfocus, onmousedown, onmouseup, 
'onmouseout, onsubmit, onreset, onpropertychange等。

'下面是网友写的一个简单的应用
Option Explicit
'定义变量
Dim oWin32 'win32对象
Dim sTitle '页面标题
Dim arrLinkText '链接文字数组
Dim sLinkText '链接文字
Dim sEventName '操作事件名称
Dim iWaitTime '两次操作时间间隔
Dim iIdentifyTimeOut '识别对象超时时间
Dim n '循环变量

call main()
Sub Main()
    Set oWin32=createobject("wscript.shell")
    sTitle="中国雅虎首页"
    arrLinkText=split("财经;图片;旅游;商品;天猫;tigerj",";",-1,1)
    sEventName="onmouseover" '鼠标移动到对象上的事件
    iWaitTime=1 '操作间隔等1秒
    iIdentifyTimeOut = 3
    If Browser("title:=" &sTitle).Exist Then
        Browser("title:=" &sTitle).Close '若刚开始就存在中国雅虎首页,则关闭即可。
    End If
    oWin32.Run("http://cn.yahoo.com/") '进入中国雅虎首页
    
    For n = 0 To ubound(arrLinkText)
    wait iWaitTime
    sLinkText=arrLinkText(n)
    
     moveMouseOnIt    
    Next
    
    Browser("title:=" &sTitle).Close '执行完毕关闭浏览器
End Sub

Function moveMouseOnIt()
    '检查链接是否存在,存在再触发事件
    If Browser("title:=" &sTitle).Page("title:=" &sTitle).link("innertext:="&sLinkText,"index:=0").Exist(iIdentifyTimeOut) Then
        Browser("title:=" &sTitle).Page("title:=" &sTitle).link("innertext:="&sLinkText,"index:=0").FireEvent sEventName
       moveMouseOnIt=true
       'Reporter.ReportEvent micPass,"Trigger the event" & sEventName & " successfully."
       Reporter.ReportEvent micPass,sEventName,"Trigger the event """&sEventName&""" successfully."

    else
       moveMouseOnIt=false
       Reporter.ReportEvent micFail,sEventName,"Failed to trigger the event " & sEventName & " because of the absence of the link."
       
     
    End If
End Function

原创粉丝点击