public AutomationElement GetUpdatedAEWhenStructureChanged(AutomationElement mainWidow, AutomationPattern patternToCache = null, AutomationProperty propertyToCache = null)
{
CacheRequest cacheRequest = new CacheRequest();
cacheRequest.TreeScope = TreeScope.Element | TreeScope.Descendants | TreeScope.Children;
cacheRequest.AutomationElementMode = AutomationElementMode.Full;
cacheRequest.TreeFilter = System.Windows.Automation.Automation.RawViewCondition;
if (patternToCache != null)
{
cacheRequest.Add(patternToCache);
}
else
{
cacheRequest.Add(SelectionPattern.Pattern);
cacheRequest.Add(WindowPattern.Pattern);
cacheRequest.Add(InvokePattern.Pattern);
cacheRequest.Add(TogglePattern.Pattern);
cacheRequest.Add(ExpandCollapsePattern.Pattern);
cacheRequest.Add(ValuePattern.Pattern);
cacheRequest.Add(SelectionItemPattern.Pattern);
}
if (propertyToCache != null)
{
cacheRequest.Add(propertyToCache);
}
else
{
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(AutomationElement.AutomationIdProperty);
cacheRequest.Add(AutomationElement.ClassNameProperty);
cacheRequest.Add(AutomationElement.ControlTypeProperty);
}
AutomationElement updatedElement;
using (cacheRequest.Activate())
{
updatedElement = mainWidow.GetUpdatedCache(cacheRequest);
}
return updatedElement;
}