/// <summary>
 /// Finds for the first item which matches the given xpath.
 /// </summary>
 public ISHAutomationElement FindFirstByXPath(string xPath)
 {
     try
     {
         var xPathNavigator = new SHAutomationElementXPathNavigator(this);
         var nodeItem       = xPathNavigator.SelectSingleNode(xPath);
         return((ISHAutomationElement)nodeItem?.UnderlyingObject);
     }
     catch (System.Runtime.InteropServices.COMException)
     {
         return(null);
     }
     catch (XPathException)
     {
         return(null);
     }
 }
        /// <summary>
        /// Finds all items which match the given xpath.
        /// </summary>
        private SHAutomationElement[] FindAllByXPathBase(string xPath)
        {
            DateTime startTime = DateTime.Now;

            try
            {
                var xPathNavigator   = new SHAutomationElementXPathNavigator(this);
                var itemNodeIterator = xPathNavigator.Select(xPath);
                var itemList         = new List <SHAutomationElement>();
                while (itemNodeIterator.MoveNext() && DateTime.Now.Subtract(startTime).TotalSeconds < 1)
                {
                    var automationItem = (SHAutomationElement)itemNodeIterator.Current.UnderlyingObject;
                    itemList.Add(automationItem);
                }
                return(itemList.ToArray());
            }
            catch (Exception ex) when(ex is System.Runtime.InteropServices.COMException || ex is NullReferenceException)
            {
                return(Array.Empty <SHAutomationElement>());
            }
        }