Activate, Maximize, Restore and Minimize a Browser - Part 1



Have you ever had the need to activate, maximize or minimze a browser ? I am sure you had...but unfortunately the Browser object does not have these methods. So what do we do. I have faced this situation and so wanted to share what I did to accomplish this.
What we will do here is use two concepts. Descriptive Programming and Registering a function with an object which would make our code very neat.
The very first step with this approach is that we would be identifying a Browser object as a Window instead of a Browser. For the Windows operating system, after all, everything is a window. So we will make use of some properties within the Window object to recognize a browser. I had already covered this in another thread on QTP 10, Vista and IE8 where we do this.
OK. Before that lets understand one thing. Every window has a property called as "handle" and this is unique for each and every window. In QTP, this property is known as "hwnd". So a Browser window can also be identified with a Window Class object if we pass the handle. Open any browser and then spy on it. Get the window handle. Lets say its value is 459420. Now this browser can be identified as Window("hwnd:=459420"). So we are almost there. Since a Window object has the methods Activate, Maximize, Restore and Minimize methods, we could make use of them over here... isnt that interesting !!!!



Our code looks like above. Using the "hwnd" property is the best way to identify the browser because it is unique. However you could also make use of the "nativeclass" and "regexpwndtitle" properties which would be "IEFrame" and "Windows Internet Explorer" respectively.

Window("regexpwndtitle:=Windows Internet Explorer","nativeclass:=IEFrame").Activate

But the above code would not work when you have multiple browsers open. Thats the reason why I mentioned earlier that getting the "handle" of the window is the best technique.
So here we just showed that we could activate, maximize, restore and minimize a Browser as well !!!! Continue to read Part 2 on this topic. Enjoy the journey !!!!!

I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (0)

0 Response to "Activate, Maximize, Restore and Minimize a Browser - Part 1"

Post a Comment

Visitors

Website Counter