Exemple #1
0
        /// <summary>
        /// Get DesktopElement from x, y position
        /// </summary>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <returns></returns>
        public static DesktopElement ElementFromPoint(int xPos, int yPos)
        {
            try
            {
                var uia = UIAutomation.ElementFromPoint(new tagPOINT()
                {
                    x = xPos, y = yPos
                });

                if (!DesktopElement.IsFromCurrentProcess(uia))
                {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
                    var e = new DesktopElement(uia, true, false);
#pragma warning restore CA2000
                    e.PopulateMinimumPropertiesForSelection();

                    return(e);
                }
                else
                {
                    Marshal.ReleaseComObject(uia);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();
            }
#pragma warning restore CA1031 // Do not catch general exception types

            return(null);
        }
        /// <summary>
        /// Clone A11yElement for selection
        /// </summary>
        /// <param name="e"></param>
        /// <returns>if element is not live, don't allow clow</returns>
        public static A11yElement CloneForSelection(this A11yElement e)
        {
            if (e == null)
            {
                return(null);
            }
            if (e.PlatformObject == null)
            {
                return(null);
            }

            try
            {
                var cache = DesktopElementHelper.BuildCacheRequest(MiniumProperties, null);

                var uia = ((IUIAutomationElement)e.PlatformObject).BuildUpdatedCache(cache);
                Marshal.ReleaseComObject(cache);

                var ne = new DesktopElement(uia, true, false);
                ne.PopulateMinimumPropertiesForSelection();

                return(ne);
            }
            catch (COMException ex)
            {
                ex.ReportException();
            }

            return(null);
        }
        /// <summary>
        /// Get DesktopElement from x, y position
        /// </summary>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <returns></returns>
        public static DesktopElement ElementFromPoint(int xPos, int yPos)
        {
            try
            {
                var uia = UIAutomation.ElementFromPoint(new tagPOINT()
                {
                    x = xPos, y = yPos
                });

                if (!DesktopElement.IsFromCurrentProcess(uia))
                {
                    var e = new DesktopElement(uia, true, false);
                    e.PopulateMinimumPropertiesForSelection();

                    return(e);
                }
                else
                {
                    Marshal.ReleaseComObject(uia);
                }
            }
            catch (Exception e)
            {
                e.ReportException();
            }

            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Get DesktopElement from UIAElement interface.
        /// </summary>
        /// <param name="uia"></param>
        /// <returns></returns>
        private static DesktopElement ElementFromUIAElement(IUIAutomationElement uia)
        {
            if (uia != null)
            {
                if (!DesktopElement.IsFromCurrentProcess(uia))
                {
                    var el = new DesktopElement(uia, true, false);

                    el.PopulateMinimumPropertiesForSelection();

                    return(el);
                }
                else
                {
                    Marshal.ReleaseComObject(uia);
                }
            }

            return(null);
        }