/// <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); } } #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> /// 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); }