<div>Hi,<br></div><div><br></div><div>I&#39;m using UIAutomation framework with IronPython to test our application.</div><div>For WPF dialogs it works perfectly. But I run into trouble when try to use it for some older dialogs.</div>
<div><br></div><div>The problem:  With IronPython I&#39;m not able to get proper control type. Any controls appears as ControlType.Pane </div><div><br></div><div>Simple example: (with windows calculator)</div><div>--------------------------------------- IP Code ------------------------------------------------------</div>
<div>import clr<div><br></div><div>clr.AddReference(&#39;UIAutomationClient&#39;)</div><div>clr.AddReference(&#39;UIAutomationTypes&#39;)</div><div><br></div><div>from System.Windows.Automation import *</div><div><br></div>
<div>_rootElement = AutomationElement.RootElement</div><div><br></div><div>if __name__ == &#39;__main__&#39;:</div><div><br></div><div style="margin-left: 40px">    nameCondition = PropertyCondition(AutomationElement.NameProperty, &quot;Calculator&quot;)</div>
<div style="margin-left: 40px">    typeCondition = PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window)</div><div style="margin-left: 40px">    calcCondition = AndCondition(nameCondition, typeCondition)</div>
<div style="margin-left: 40px">    appCalc = _rootElement.FindFirst(TreeScope.Children, calcCondition)</div><div style="margin-left: 40px">        <br></div><div style="margin-left: 40px">    if appCalc is not None:</div>
<div style="margin-left: 40px">        </div><div style="margin-left: 80px">        isFocusable = appCalc.GetCurrentPropertyValue(AutomationElement.IsKeyboardFocusableProperty, True)</div><div style="margin-left: 80px">        <br>
</div><div style="margin-left: 80px">        if isFocusable:</div><div style="margin-left: 120px">#appCalc.SetFocus()   #calling this raise: System.InvalidOperationException</div><div style="margin-left: 120px">pass</div>
<div style="margin-left: 80px">        <br></div><div style="margin-left: 80px">        contList = appCalc.FindAll(TreeScope.Subtree, Condition.TrueCondition)</div><div style="margin-left: 80px">        </div><div style="margin-left: 80px">
        for elm in contList:</div><div style="margin-left: 120px">progName = elm.Current.ControlType.ProgrammaticName</div><div style="margin-left: 120px">print progName</div></div><div style="margin-left: 0px">-----------------------------------------------------------------------------------------------------------</div>
<div style="margin-left: 0px">above code produce following output:</div><div style="margin-left: 0px"><br></div><div style="margin-left: 0px">ControlType.Window<br>ControlType.Pane<br>ControlType.Pane<br>ControlType.Pane<br>
ControlType.Pane<br>ControlType.Pane<br>.</div><div style="margin-left: 0px">.</div><div style="margin-left: 0px">.<br> </div><div style="margin-left: 0px">            </div><div style="margin-left: 0px">similar C# code works as expected</div>
<div style="margin-left: 0px">            ------------------------------------------ C# Code ---------------------------------------------------</div><div style="margin-left: 0px">using System;<div>using System.Collections.Generic;</div>
<div>using System.Linq;</div><div>using System.Text;</div><div>using System.Windows.Automation;</div><div>using Automation = System.Windows.Automation;</div><div><br></div><div>namespace UIAutTest</div><div>{</div><div>    class Program</div>
<div>    {</div><div style="margin-left: 40px">        static void Main(string[] args)</div><div style="margin-left: 40px">        {</div><div style="margin-left: 40px">            AutomationElement rootElement = AutomationElement.RootElement;</div>
<div style="margin-left: 40px"><br></div><div style="margin-left: 40px">            Automation.Condition nameCondition = new PropertyCondition(AutomationElement.NameProperty, &quot;Calculator&quot;);</div><div style="margin-left: 40px">
            Automation.Condition controlCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);</div><div style="margin-left: 40px">            Automation.Condition calcCondition = new AndCondition(nameCondition, controlCondition);</div>
<div style="margin-left: 40px">            AutomationElement appCalc = rootElement.FindFirst(TreeScope.Children, calcCondition);</div><div style="margin-left: 40px"><br></div><div style="margin-left: 40px"><br></div><div style="margin-left: 80px">
            if (appCalc != null)</div><div style="margin-left: 80px">            {</div><div style="margin-left: 80px">                appCalc.SetFocus();</div><div style="margin-left: 80px"><br></div><div style="margin-left: 80px">
                AutomationElementCollection allCont = appCalc.FindAll(TreeScope.Subtree, Condition.TrueCondition);</div><div style="margin-left: 120px">                foreach (AutomationElement elm in allCont)</div><div style="margin-left: 120px">
                {</div><div style="margin-left: 120px">                    string contProgNam = elm.Current.ControlType.ProgrammaticName;</div><div style="margin-left: 120px">                    Console.WriteLine(contProgNam);</div>
<div style="margin-left: 120px">}</div><div style="margin-left: 80px">            }</div><div style="margin-left: 80px"><br></div><div style="margin-left: 40px">        }</div><div>    }</div><div>}</div><div>---------------------------------------------------------------------------------------------</div>
<div>C# code produce this output:</div><div><br></div><div>ControlType.Window<br>ControlType.Edit<br>ControlType.CheckBox<br>ControlType.CheckBox<br>ControlType.Group<br>ControlType.Button<br>ControlType.RadioButton<br>ControlType.RadioButton<br>
ControlType.RadioButton<br>ControlType.RadioButton<br>ControlType.Group<br>ControlType.Group<br>ControlType.RadioButton<br>ControlType.RadioButton<br>ControlType.RadioButton<br>ControlType.Button<br>.<br></div><div>.</div>
<div><br></div><div><br></div><div>Does anybody know why ControlType property retrieved by IP code is different then ControlType retrieved by C# ?<br></div><div>Others element properties retrieved by IP code seems to by OK.</div>
<div><br></div><div>Info:<br></div><div>Windows Vista Business, SP2</div><div>IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.4200</div><div><br></div><div>Thanks,<br>Jozef<br></div><div><br></div></div><div>PS:  Duane Kaufman, send similar question :  <a href="http://lists.ironpython.com/htdig.cgi/users-ironpython.com/2009-June/010693.html" target="_blank">http://lists.ironpython.com/htdig.cgi/users-ironpython.com/2009-June/010693.html</a>.</div>

<div>But, no one answer him.  </div>