[IronPython] What's wrong with IronPython (UIAutomation)

Jozef jozef.alexovic at gmail.com
Wed Nov 11 11:15:58 CET 2009


Thanks for your response.
Solution to my problem is to first instantiate AutomationElement from dll,
not from IronPython.
Then all subsequent AutomationElement retrieved from IronPython looks ok.

Jozef

2009/11/6 Shri Borde <Shri.Borde at microsoft.com>

>  In the past, there had been issues with UIAutomation as mentioned in
> http://blogs.msdn.com/shrib/archive/2008/03/24/ironpython-cannot-call-automationelement-fromhandle.aspx.
> This could be related. You could try it on Win7 to see if its fixed.
>
>
>
> You can also try the techniques mentioned in
> http://blogs.msdn.com/shrib/archive/2008/03/24/what-if-a-c-snippet-does-not-work-when-transliterated-to-ironpython.aspxto narrow down the problem.
>
>
>
> *From:* users-bounces at lists.ironpython.com [mailto:
> users-bounces at lists.ironpython.com] *On Behalf Of *Jozef
> *Sent:* Friday, November 06, 2009 6:20 AM
> *To:* users at lists.ironpython.com
> *Subject:* [IronPython] What's wrong with IronPython (UIAutomation)
>
>
>
> Hi,
>
>
>
> I'm using UIAutomation framework with IronPython to test our application.
>
> For WPF dialogs it works perfectly. But I run into trouble when try to use
> it for some older dialogs.
>
>
>
> The problem:  With IronPython I'm not able to get proper control type. Any
> controls appears as ControlType.Pane
>
>
>
> Simple example: (with windows calculator)
>
> --------------------------------------- IP Code
> ------------------------------------------------------
>
> import clr
>
>
>
> clr.AddReference('UIAutomationClient')
>
> clr.AddReference('UIAutomationTypes')
>
>
>
> from System.Windows.Automation import *
>
>
>
> _rootElement = AutomationElement.RootElement
>
>
>
> if __name__ == '__main__':
>
>
>
> nameCondition = PropertyCondition(AutomationElement.NameProperty,
> "Calculator")
>
> typeCondition = PropertyCondition(AutomationElement.ControlTypeProperty,
> ControlType.Window)
>
> calcCondition = AndCondition(nameCondition, typeCondition)
>
> appCalc = _rootElement.FindFirst(TreeScope.Children, calcCondition)
>
>
>
> if appCalc is not None:
>
>
>
> isFocusable =
> appCalc.GetCurrentPropertyValue(AutomationElement.IsKeyboardFocusableProperty,
> True)
>
>
>
> if isFocusable:
>
> #appCalc.SetFocus()   #calling this raise: System.InvalidOperationException
>
> pass
>
>
>
> contList = appCalc.FindAll(TreeScope.Subtree, Condition.TrueCondition)
>
>
>
> for elm in contList:
>
> progName = elm.Current.ControlType.ProgrammaticName
>
> print progName
>
>
> -----------------------------------------------------------------------------------------------------------
>
> above code produce following output:
>
>
>
> ControlType.Window
> ControlType.Pane
> ControlType.Pane
> ControlType.Pane
> ControlType.Pane
> ControlType.Pane
> .
>
> .
>
> .
>
>
>
>
> similar C# code works as expected
>
> ------------------------------------------ C# Code
> ---------------------------------------------------
>
> using System;
>
> using System.Collections.Generic;
>
> using System.Linq;
>
> using System.Text;
>
> using System.Windows.Automation;
>
> using Automation = System.Windows.Automation;
>
>
>
> namespace UIAutTest
>
> {
>
> class Program
>
> {
>
> static void Main(string[] args)
>
> {
>
> AutomationElement rootElement = AutomationElement.RootElement;
>
>
>
> Automation.Condition nameCondition = new
> PropertyCondition(AutomationElement.NameProperty, "Calculator");
>
> Automation.Condition controlCondition = new
> PropertyCondition(AutomationElement.ControlTypeProperty,
> ControlType.Window);
>
> Automation.Condition calcCondition = new AndCondition(nameCondition,
> controlCondition);
>
> AutomationElement appCalc = rootElement.FindFirst(TreeScope.Children,
> calcCondition);
>
>
>
>
>
> if (appCalc != null)
>
> {
>
> appCalc.SetFocus();
>
>
>
> AutomationElementCollection allCont = appCalc.FindAll(TreeScope.Subtree,
> Condition.TrueCondition);
>
> foreach (AutomationElement elm in allCont)
>
> {
>
> string contProgNam = elm.Current.ControlType.ProgrammaticName;
>
> Console.WriteLine(contProgNam);
>
> }
>
> }
>
>
>
> }
>
> }
>
> }
>
>
> ---------------------------------------------------------------------------------------------
>
> C# code produce this output:
>
>
>
> ControlType.Window
> ControlType.Edit
> ControlType.CheckBox
> ControlType.CheckBox
> ControlType.Group
> ControlType.Button
> ControlType.RadioButton
> ControlType.RadioButton
> ControlType.RadioButton
> ControlType.RadioButton
> ControlType.Group
> ControlType.Group
> ControlType.RadioButton
> ControlType.RadioButton
> ControlType.RadioButton
> ControlType.Button
> .
>
> .
>
>
>
>
>
> Does anybody know why ControlType property retrieved by IP code is
> different then ControlType retrieved by C# ?
>
> Others element properties retrieved by IP code seems to by OK.
>
>
>
> Info:
>
> Windows Vista Business, SP2
>
> IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.4200
>
>
>
> Thanks,
> Jozef
>
>
>
> PS:  Duane Kaufman, send similar question :
> http://lists.ironpython.com/htdig.cgi/users-ironpython.com/2009-June/010693.html
> .
>
> But, no one answer him.
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20091111/15ba187c/attachment.html>


More information about the Ironpython-users mailing list