QTP调出Web Image对象的右键菜单的方法

上一篇 / 下一篇  2011-02-17 16:20:40 / 个人分类:QTP

thanks for authoryabest

Web里很多对象都有Click方法(object.Click [x], [y], [BUTTON]),带上micRightBtn参数,都能实现右键点击调出右键菜单的操作。
可是不知为何,Image对象就是不能右键点击,不管是否带上micRightBtn参数,Click执行的都是左键点击操作,所以无法调出右键菜单。
朋友要求,研究了一番,找出替代的解决方法,写了一个函数,可供大家参考



SelectImageMenu browser("test").Page("test").Image("image001"), "R"

'================================================================
' FUNCTION NAME:
'        SelectImageMenu
' FUNCTION DESCRIPTION:
'        Use this function to right-click on a image object and select the pop-up menu
' FUNCTION USAGE:
'        ret = SelectImageMenu(browser("test").Page("test").Image("image001"), "R")
' FUNCTION PARAMETER        
'        ImageObject : The web image object
'        MenuKey : The hot key of pop-up menu item you will select
' FUNCTION RETURN:
'        Return 0 when successfully, or return -1 when fail
'================================================================
Function SelectImageMenu(ImageObject, MenuKey)

        Dim wshShell
        Dim ieServerObject

        Dim x1, y1

        'Get the ie server object
        Set ieServerObject = Window("regexpwndclass:=IEFrame").WinObject("regexpwndclass:=Internet Explorer_Server")

        'get the image position
        x1 = CInt(ImageObject.GetROProperty("abs_x"))
        y1 = CInt(ImageObject.GetROProperty("abs_y"))

        'right-click on image through ie object
        ieServerObject.Click x1, y1, micRightBtn
        wait 1

        'Select the menu item by press hot key
        Set wshShell = CreateObject("WScript.Shell")
        wshShell.SendKeys MenuKey
        wait 1
   
        SelectImageMenu = 0
        
End Function


说明:

因为那右键弹出菜单QTP无法识别,所以QTP无法操作这菜单,只能用键盘按键来代替鼠标选择

键盘按键可以是热键,如“复制(C)”这一菜单项,可以用按键C来选择,MenuKey就设为"C"。

键盘按键也可以是下箭头和回车键,如要选择第三个菜单项,可以按三下下箭头和回车键来选择,MenuKey就设为"{DOWN}{DOWN}{DOWN}{ENTER}"。这样没有热键的菜单也可以选择了,前提是菜单项目是固定的,不是可变的。

TAG:

 

评分:0

我来说两句

Open Toolbar