/// <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 { } return(null); }
/// <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); }
/// <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) { try { if (e != null && e.PlatformObject != null) { 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) { } return(null); }