[browsershots-factories] Determine how to get a window for various browsers

Johann C. Rocholl johann at browsershots.org
Sun Aug 5 04:00:50 CEST 2007


On 8/4/07, Rajagopal V wrote:
> I have looked at the code that gets the hWnd object and using that object to
> scroll down for screenshots. I would like to know what tools are used to
> figure out how the hWnd object is obtained. This isnt a browsershots
> question per se, but Im curious to know how to arrive at finding the window
> object for various browsers. For e.g. if a new browser were to be introduced
> as a factory, how would you figure out the way to get the hWnd object?

Usually I just experiment with Python scripts until I find a way.

My favorite method works like this:
1. Get the hWnd at the center of the screen.
2. Print window class and try to scroll.
3. Get the parent window and go back to step 2.

Here's a Python code snippet to do that:

def find_scrollable(verbose=True):
    hWnd = win32gui.WindowFromPoint((1024 / 2, 768 / 2))
    for parent_level in range(20):
        if not hWnd:
            return None
        if verbose:
            print 'handle', hWnd
            print 'classname', win32gui.GetClassName(hWnd)
            print 'text', win32gui.GetWindowText(hWnd)
            print
        if win32gui.GetClassName(hWnd) == 'OperaWindowClass':
            return hWnd
        hWnd = win32gui.GetParent(hWnd)

You can also try to run the Windows browser modules directly from the
command line, and maybe add some print statements for debugging. See
for example the last lines in this file:

http://trac.browsershots.org/browser/branches/shotfactory-django/shotfactory04/gui/windows/opera.py
http://svn.browsershots.org/branches/shotfactory-django/shotfactory04/gui/windows/opera.py
$ python gui/windows/opera.py

Cheers,
Johann


More information about the browsershots-factories mailing list