|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
Issues with IronPython UI AutomationHi,
I am new to the group, and trying to educate myself on using IronPython for UI Automation. I found a code snippet (in C#) to pattern some Python after on the web: (from http://refact.blogspot.com/2009/03/ui-automation-library.html), which is supposed to check to see that a keypress of the "1" button makes a "1" appear in the calculator display. I am running into a problem where I can't find the Edit control programmatically. // .. Launch Calc Process Process[] processes = Process.GetProcessesByName("calc"); AutomationElement _mainWindow= AutomationElement.FromHandle(processes[0].MainWindowHandle); AutomationElement lButton =_mainWindow.FindFirst( TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "1")); ((InvokePattern)(lButton .GetCurrentPattern(InvokePattern.Pattern))).Invoke(); AutomationElement lScreen = _mainWindow.FindFirst( TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); string lDisplayText = (string)lScreen.GetCurrentPropertyValue(ValuePattern.ValueProperty); Assert.Equals("1",lDisplayText); processes [0].Close(); My Python code to attempt something similar: import clr clr.AddReference('UIAutomationClient') clr.AddReference('UIAutomationTypes') from System.Windows.Automation import * # unlike C# example, make sure Windows Calculator is running before running this script tops = AutomationElement.RootElement.FindAll(TreeScope.Children, Condition.TrueCondition) for elem in tops: #print "Window %s is available" % elem.GetCurrentPropertyValue(AutomationElement.NameProperty) if elem.GetCurrentPropertyValue(AutomationElement.NameProperty) == 'Calculator': print "Calculator found! Total of %d UI elements" % len(elem.FindAll(TreeScope.Children, Condition.TrueCondition)) NameCondition = PropertyCondition(AutomationElement.NameProperty, "1") lButton = elem.FindFirst(TreeScope.Children, NameCondition) print lButton EditCondition = PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit) lScreen = elem.FindFirst(TreeScope.Children, EditCondition) print lScreen The output looks like: Calculator found! Total of 74 UI elements <System.Windows.Automation.AutomationElement object at 0x000000000000002B [Syste m.Windows.Automation.AutomationElement]> None which seems to indicate that the Edit control was not found, but I can find it using a tool like UISpy. Why can't I search for the Edit control in this window and find it? Thanks in advance, Duane _______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com |
| Free embeddable forum powered by Nabble | Forum Help |