|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
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@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com |
|
|
Re: What's wrong with IronPython (UIAutomation)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.aspx
to narrow down the problem. From:
users-bounces@... [mailto:users-bounces@...] On
Behalf Of Jozef 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 . . 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 . 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, 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@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com |
|
|
Re: What's wrong with IronPython (UIAutomation)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@...>
_______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com |
| Free embeddable forum powered by Nabble | Forum Help |