This article demonstrates a quick tip to activate, minimize or maximize browsers. Unlike a Standard Windows Window
object, Browser does not support theActivate
, Minimize
, Maximize
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"
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!