[IronPython] [python] Re: Getting window properties

Michael Foord fuzzyman at voidspace.org.uk
Tue Jan 8 20:17:10 CET 2008


Jim Hugunin wrote:
> Another option would be to use the System.Windows.Automation library - new in .NET 3.0.  It's a lot easier to use than the native APIs when it works for you.  This sample will print the titles of all the top-level windows.
>
> --------------------------------------
> import clr
> clr.AddReference('UIAutomationClient')
> clr.AddReference('UIAutomationTypes')
> from System.Windows.Automation import *
>
> tops = AutomationElement.RootElement.FindAll(TreeScope.Children, Condition.TrueCondition)
> for elem in tops:
>     print elem.GetCurrentPropertyValue(AutomationElement.NameProperty)
>   

Wow - I didn't know there was an automation library in .NET 3!

Thanks

Michael

> ----------------------------------------
>
> Thanks - Jim
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Fuzzyman
> Sent: Tuesday, January 08, 2008 2:34 AM
> To: Discussion of IronPython
> Subject: Re: [IronPython] Getting window properties
>
> 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:
> http://www.ironpython.info/index.php/Access_Unmanaged_Code_with_Dynamic_P/Invoke
>
> I hope this is helpful.
>
> Michael Foord
> http://www.manning.com/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
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>>     
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>   




More information about the Ironpython-users mailing list