[IronPython] What's wrong with IronPython (UIAutomation)
Jozef
jozef.alexovic at gmail.com
Fri Nov 6 15:19:54 CET 2009
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20091106/80f3aa59/attachment.html>
More information about the Ironpython-users
mailing list