public WindowElement Find(IntPtr windowHandle) { var handle = WindowsApiFunctions.GetWindowHandles().FirstOrDefault(i => i.Handle == windowHandle); if (handle == null) { throw new ElementException(string.Format("Unable to find window for handle: {0}", windowHandle)); } return(new WindowElement(AutomationElement.FromHandle(handle.Handle))); }
public WindowElement Find(string titleRegEx) { var handle = WindowsApiFunctions.GetWindowHandles().FirstOrDefault(i => Regex.IsMatch(i.Title, titleRegEx, RegexOptions.IgnoreCase)); if (handle == null) { throw new ElementException(string.Format("Unable to find window for title regex {0}", titleRegEx)); } return(new WindowElement(AutomationElement.FromHandle(handle.Handle))); }
public ElementActionResult Click() { if (Item == null) { return(ElementActionResult.CreateError("Automation element not provided")); } object invokePattern = null; try { if (Item.TryGetCurrentPattern( InvokePattern.Pattern, out invokePattern)) { ((InvokePattern)invokePattern).Invoke(); Thread.Sleep(100); } else { Item.SetFocus(); Thread.Sleep(300); var p = default(System.Windows.Point); if (Item.TryGetClickablePoint(out p)) { WindowsApiFunctions.MouseClick(MouseClickType.Left, (int)p.X, (int)p.Y); } else { var calculatedPoint = new Point( Convert.ToInt32(Item.Current.BoundingRectangle.X + (Item.Current.BoundingRectangle.Width / 2)), Convert.ToInt32(Item.Current.BoundingRectangle.Y + (Item.Current.BoundingRectangle.Height / 2))); WindowsApiFunctions.MouseClick(MouseClickType.Left, calculatedPoint.X, calculatedPoint.Y); } } } catch (Exception ex) { return(ElementActionResult.CreateError(ex, "Automation element {0} text operation failed with external error {1}", Item.Current.AutomationId, ex.Message)); } return(ElementActionResult.CreateSuccess()); }
public IEnumerable <WindowElement> FindAllForProcess(int processId) { return(WindowsApiFunctions.GetWindowHandles().Where(i => i.ProcessId == processId).Select(i => new WindowElement(AutomationElement.FromHandle(i.Handle)))); }
public void Maximize() { WindowsApiFunctions.SetWindowState(Handle, WindowState.SW_SHOWMAXIMIZED); }
public void Minimize() { WindowsApiFunctions.SetWindowState(Handle, WindowState.SW_FORCEMINIMIZE); }
public void Activate() { WindowsApiFunctions.SetWindowState(Handle, WindowState.SW_SHOWNORMAL); WindowsApiFunctions.SetForegroundWindow(Handle); }
public void Close() { WindowsApiFunctions.CloseWindow(new IntPtr(Item.Current.NativeWindowHandle)); }