QTP 自定义方法将IE最大化最小化

This article demonstrates a quick tip to activate, minimize or maximize browsers. Unlike a Standard Windows Window object, Browser does not support theActivateMinimizeMaximize methods. Therefore, we can create our custom function and tie it with the Browser object using RegisterUserFunc.

The only trick is to retrieve the Browser Handle and substitute the handle in the description of a Window object, and use the Window’s Activate method instead.

ACTIVATE BROWSER

Function BrowserActivate(Object)
    Dim hWnd
 
    hWnd = Object.GetROProperty("hwnd")
 
    On Error Resume Next
        Window("hwnd:=" & hWnd).Activate
 
        If Err.Number <> 0 Then
            Window("hwnd:=" & Browser("hwnd:=" & hWnd).Object.hWnd).Activate
            Err.Clear
        End If
    On Error Goto 0
End Function
 
RegisterUserFunc "Browser", "Activate", "BrowserActivate"


After registering the BrowserActivate function with the Browser object as Activate we can use it just like we would use it for a Window object:

Browser("title:=Relevant Codes.*").Activate


BrowserActivate can be extended to maximize and minimize a browser window as well. The only extra statement to be included in the function would be the maximize and minimize methods of the window object.

MINIMIZE BROWSERS

Function BrowserMinimize(Object)
    Dim hWnd
 
    hWnd = Object.GetROProperty("hwnd")
 
    On Error Resume Next
        Window("hwnd:=" & hWnd).Activate
 
        If Err.Number <> 0 Then
            hWnd = Browser("hwnd:=" & hWnd).Object.hWnd
            Window("hwnd:=" & hWnd).Activate
            Err.Clear
        End If
 
        Window("hwnd:=" & hWnd).Minimize
    On Error Goto 0
End Function
 
RegisterUserFunc "Browser", "Minimize", "BrowserMinimize"




MAXIMIZE BROWSERS

Function BrowserMaximize(Object)
    Dim hWnd
 
    hWnd = Object.GetROProperty("hwnd")
 
    On Error Resume Next
        Window("hwnd:=" & hWnd).Activate
 
        If Err.Number <> 0 Then
            hWnd = Browser("hwnd:=" & hWnd).Object.hWnd
            Window("hwnd:=" & hWnd).Activate
            Err.Clear
        End If
 
        Window("hwnd:=" & hWnd).Maximize
    On Error Goto 0
End Function
 
RegisterUserFunc "Browser", "Maximize", "BrowserMaximize"



If you would like to use the above 3 methods through a single function or class, they can be coupled together through Execute statements or through If-Then or Switch-Case blocks. Happy reading!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值