In about 30% cases search for my top element returns null. Occures randomly only on Win10. Even within same test if on earlier steps it found top form it might not find it next time.
AutomationElement shell = AutomationElement.RootElement.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, _shellElementName));
if (shell == null)
{
shell = AutomationElement.RootElement.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.AutomationIdProperty, _shellElementId));
}
_shellElementName & _shellElementId are consts and top form never changes. I also triedTreeScope.Descendants -- made no difference except being slower. Subsequent
TreeWalker walker = TreeWalker.ControlViewWalker;
AutomationElement childElement = walker.GetFirstChild(AutomationElement.RootElement);
throws exception:
System.Windows.Automation.ElementNotAvailableException: Element not available ---> System.ArgumentException: Value does not fall within the expected range.
System.ArgumentException: Value does not fall within the expected range.
at UIAutomationClient.IUIAutomationTreeWalker.GetFirstChildElementBuildCache(IUIAutomationElement element, IUIAutomationCacheRequest cacheRequest)
at System.Windows.Automation.TreeWalker.GetFirstChild(AutomationElement element, CacheRequest request)
System.Windows.Automation.ElementNotAvailableException: Element not available ---> System.ArgumentException: Value does not fall within the expected range.
at UIAutomationClient.IUIAutomationTreeWalker.GetFirstChildElementBuildCache(IUIAutomationElement element, IUIAutomationCacheRequest cacheRequest)
at System.Windows.Automation.TreeWalker.GetFirstChild(AutomationElement element, CacheRequest request)
--- End of inner exception stack trace ---
at System.Windows.Automation.TreeWalker.GetFirstChild(AutomationElement element, CacheRequest request)
at Test.CodedUI.Desktop.Controls.ControlNavigator.GetChildrenNames(AutomationElement automationElement)
Any suggestions?
AutomationElement shell = AutomationElement.RootElement.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, _shellElementName));
if (shell == null)
{
shell = AutomationElement.RootElement.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.AutomationIdProperty, _shellElementId));
}
_shellElementName & _shellElementId are consts and top form never changes. I also triedTreeScope.Descendants -- made no difference except being slower. Subsequent
TreeWalker walker = TreeWalker.ControlViewWalker;
AutomationElement childElement = walker.GetFirstChild(AutomationElement.RootElement);
throws exception:
System.Windows.Automation.ElementNotAvailableException: Element not available ---> System.ArgumentException: Value does not fall within the expected range.
System.ArgumentException: Value does not fall within the expected range.
at UIAutomationClient.IUIAutomationTreeWalker.GetFirstChildElementBuildCache(IUIAutomationElement element, IUIAutomationCacheRequest cacheRequest)
at System.Windows.Automation.TreeWalker.GetFirstChild(AutomationElement element, CacheRequest request)
System.Windows.Automation.ElementNotAvailableException: Element not available ---> System.ArgumentException: Value does not fall within the expected range.
at UIAutomationClient.IUIAutomationTreeWalker.GetFirstChildElementBuildCache(IUIAutomationElement element, IUIAutomationCacheRequest cacheRequest)
at System.Windows.Automation.TreeWalker.GetFirstChild(AutomationElement element, CacheRequest request)
--- End of inner exception stack trace ---
at System.Windows.Automation.TreeWalker.GetFirstChild(AutomationElement element, CacheRequest request)
at Test.CodedUI.Desktop.Controls.ControlNavigator.GetChildrenNames(AutomationElement automationElement)
Any suggestions?