UI Automation
hi,
Is UI Automation possible for any application ..
I tried the delegates based on patterns & events on IE 6.0 xp . SP2 .. It more or less works ..
But when i tried on Outlook Express with same delegates .. Many delegates doesn't response .. Selection Pattern , ToggleSatepatterns etc...
Plz let me know issue ..
sorry for my english..
Thanks & Regards
sachin K.
Could you please provide more information on what you are trying to do and what libraries you are trying to do it with. UI automation is a pretty generic term. Are you attempting to use the VSTO library to automate Office or are trying to use something else?
Michael Taylor - 10/9/06
Hi Taylor ,
Well to be specific to automation. I am using System.windows.Automation namespace.
MSDN Documentation says control has pattern support .. such as Invokepattern for button , Selectionpattern for ListItem .. etc.. So we can have delegates for different properties or Events..
Now the problem is when i try to fix the AutomationElement to some application .. such as "Outlook" or "Excel" or "iexplorer" etc. with Treescope as decendents .. i get very surprising results ..
1. Some control Responds well to the Delegates and some do not ..
Example .. I have seen Drop down button reponding to "invokepattern" but "Button" don't..
2. Some Checkbox Reponds to ToggleProperty change but other checkBox don't though in bath case it supports .. TogglePattern
i have verified using :...
AutomationPattern[] patterns;
patterns = focusedElement.GetSupportedPatterns();
foreach (AutomationPattern pattern in patterns)
{
// This displays on the Form.
Feedback ("ProgrammaticName: " + pattern.ProgrammaticName);
Feedback("PatternName: " + Automation.PatternName(pattern));
}
Like wise i have encountered many issues.. I am not getting of such behaviour.
Last but not the least.. MSDN say TablePattern is supported for "Excel WorkSheet " and hopefully "griditempattern " .. I want to get Cell information , Select Range from Excel WorkSheet .. etc all with ( System.Windows.Automation ) class.
Syntax for delagates ( Only sample )
1. focusHandler =
new AutomationFocusChangedEventHandler(OnFocusChange);
2.
invokeHandler = new AutomationEventHandler(OnInvoke);
Automation.AddAutomationEventHandler(
InvokePattern.InvokedEvent,
targetApp,
TreeScope.Element | TreeScope.Descendants,
invokeHandler);Plz let me know the issue .. What am i missing.
Thanks & ragards
Sachin K. Rana ..
Ahh I see you are using some of new 3.0 stuff. In that case you should post your questions to the v3.0 forums (specificially the Microsoft UI Automation forum for this question). I will move your post to Automation forum where someone will hopefully be able to help you out.
Michael Taylor - 10/11/06
Hi Taylor,
Yes this is a v3.0 stuff.
Thanks for your information & suggestion.. I will thankful to you if i get any thing regarding UI Automation .. from anywhere..
Thanks & Regards
Sachin k. Rana.
One thing you can do is use UISpy (which comes with the SDK) to look at the UI elements for control pattern support and to listen for events. This is a good way of verifying what events you can actually expect to receive.
There does appear to be a problem with Invoke in some circumstances.
If you can tell me precisely where you are not seeing ToggleStateProperty property-changed events, I will investigate.
Thanks.
hi,
From where i can get UIspy .exe as a seperate download.. I don't find it getting installed as a part of SDK in my case..
Ok.. You can try MS-Excel .. for checking the TogglestateProperty.. My sequence of Code goes ....
RegistrationfocusHandler =
new AutomationFocusChangedEventHandler(OnFocusChange);
Automation.AddAutomationFocusChangedEventHandler(focusHandler);
CheckBoxHandle =
new AutomationPropertyChangedEventHandler(OnCheckChange);
Automation.AddAutomationPropertyChangedEventHandler(
targetApp,
TreeScope.Element| TreeScope.Descendants,
CheckBoxHandle,
ss TogglePattern.ToggleStateProperty );
Handler
1.
private void OnCheckChange(object src, AutomationEventArgs e)
{
try
{
AutomationElement CheckboxElement = src as AutomationElement;
TogglePattern CheckboxPattern =
CheckboxElement.GetCurrentPattern(TogglePattern.Pattern)
as TogglePattern;
Feedback("EVENT_OBJECT_SELECTION " + " NAME " + CheckboxElement.GetCurrentPropertyValue(AutomationElement.NameProperty) + " ROLE " + CheckboxElement.Current.ControlType.ProgrammaticName + " STATE " + CheckboxPattern.Current.ToggleState);
}
catch (InvalidOperationException IOE)
{ }
catch (Exception Ex)
{ }
}
2.
private void OnFocusChange(object src, AutomationFocusChangedEventArgs e)
{
AutomationElement focusedElement = src as AutomationElement;
AutomationPattern[] patterns;
Feedback("EVENT_OBJECT_FOCUS " + " Name " + focusedElement.GetCachedPropertyValue(AutomationElement.NameProperty ) + " ROLE " + focusedElement.Current.ControlType.ProgrammaticName );
patterns = focusedElement.GetSupportedPatterns();
foreach (AutomationPattern pattern in patterns)
{
Feedback ("ProgrammaticName: " + pattern.ProgrammaticName);
Feedback("PatternName: " + Automation.PatternName(pattern));
}
OutputEVENT_OBJECT_FOCUS Name Merge cells ROLE ControlType.CheckBox
ProgrammaticName: TogglePatternIdentifiers.Pattern
PatternName: Toggle
Now ,, I don't see OnCheckChange() Responding .. ?
I also want to understand the reason of why "
AutomationFocusChangedEventHandler()" has been made generic .. i.e no AutomationElement specification. no Treescope etc..
Thanks & Regards
Sachin K. Rana
hi,
Can i know the contents of Excel cell purely with System.Windows.Automation namespace ..
Thanks & Regards
Sachin K. Rana.
You should find UISpy.exe in the \bin folder of your SDK installation. Documentation is under .NET Framework Development / Tools / Development Tools.
The FocusChanged event is global because it is a system event. Individual UI elements do not raise this event.
UI Automation support for Excel is, unfortunately, limited at present.