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

--内容出自网友 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值