[IronPython] Getting window properties

Fuzzyman fuzzyman at voidspace.org.uk
Tue Jan 8 02:34:03 PST 2008

Marcus Patino Pan wrote:

> Hello,
> I wondered if you could help me. I have IronPython working fine, but 
> what I would like to do is use it to test another application. I have 
> worked out how to use sendkeys but to do proper testing I need to be 
> able to check if the correct window has appeared on screen, so need to 
> check some of its properties, like its title. I’ve been looking on the 
> internet for examples but with no luck.
> Could someone point me in the right direction?

We do a bit of this at Resolver, but mainly do 'in process' testing 
where we have access to the forms as .NET objects.

The functions you want live mainly in User32.dll, which is unmanaged 
code. There are functions like GetForegroundWindow, which returns a 
window handle. From this you can determine the title of the window etc. 
You can also send mouse moves and button clicks, so it is possible to 
interact with applications in a completely 'black-box' manner.

Unfortunately, although some parts of this are straightforward, we had 
real problems when trying to do things like interact with menus 
(particularly context menus) using this technique.

The bad news is that because these functions live in unmanaged code, you 
need attributes to work with them. We have some stub C# at Resolver that 
exposes those functions to IronPython. *However*, I recently discovered 
Seo's implementation of ctypes for IronPython (part of FePy but should 
work fine with a standard build of IronPython). This allows you to do 
'dynamic platform invoke', meaning you can call these functions from 
straight IronPython!

There is a minimal example at:

I hope this is helpful.

Michael Foord

> Many Thanks
> Marcus
> This email and any files transmitted with it are confidential and 
> intended solely for the use of the individual or entity to whom they 
> are addressed ("the addressee"). If you have received this email in 
> error please notify the system manager at System C Healthcare plc. 
> This email and its attachments (if any) contain(s) confidential 
> information the property of System C Healthcare plc and is/are 
> intended only for the addressee. If you are not the addressee you 
> should not use, disseminate, distribute or copy this e-mail or any 
> attachment.
> System C Healthcare plc, Registered Office, Brenchley House, Week 
> Street, Maidstone, Kent ME14 1RF Registered in England no: 1754990
>Users mailing list
>Users at lists.ironpython.com

More information about the Users mailing list