I'm using UIAutomation via COM interface in my WPF client app. Some users sometimes are taking hangs of their specific apps (like nVidia Control Panel). My app recieves that exception:
System.Runtime.InteropServices.COMException (0x80131505): Operation timed out. (Exception from HRESULT: 0x80131505) in UIAutomationClient.IUIAutomationElement.FindAll (TreeScope scope, IUIAutomationCondition condition).
I cannot reproduce this on my PC.
I've found some info about the issue.
TreeWalker (source)Both
FindAllandFindFirstare prone to this exception, which is raised when trying to find elements inWebViewthat has loaded its data recently, exception is thrown when methods try to build cache, so it might be due to trying to iterate visual tree while it is being rebuild by another thread.Replacing
FindAllwithprivate IEnumerable<WiniumElement> GetChildrens() { var elementNode = TreeWalker.ControlViewWalker.GetFirstChild(this.AutomationElement); while (elementNode != null) { yield return new WiniumElement(elementNode); elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode); } }Solves the problem. Needs further investigation. Most likely we will have to replace both
FindFirstandFindAllcalls with customTreeWalkeriteration method.This will solve the problem with not being able to get page source for views with
WebViews and not being able to find element inWebViewdue to same error.
User contributions licensed under CC BY-SA 3.0