Exemple #1
0
        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)));
        }
Exemple #2
0
        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)));
        }
Exemple #3
0
        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());
        }
Exemple #4
0
 public IEnumerable <WindowElement> FindAllForProcess(int processId)
 {
     return(WindowsApiFunctions.GetWindowHandles().Where(i => i.ProcessId == processId).Select(i => new WindowElement(AutomationElement.FromHandle(i.Handle))));
 }
Exemple #5
0
 public void Maximize()
 {
     WindowsApiFunctions.SetWindowState(Handle, WindowState.SW_SHOWMAXIMIZED);
 }
Exemple #6
0
 public void Minimize()
 {
     WindowsApiFunctions.SetWindowState(Handle, WindowState.SW_FORCEMINIMIZE);
 }
Exemple #7
0
 public void Activate()
 {
     WindowsApiFunctions.SetWindowState(Handle, WindowState.SW_SHOWNORMAL);
     WindowsApiFunctions.SetForegroundWindow(Handle);
 }
Exemple #8
0
 public void Close()
 {
     WindowsApiFunctions.CloseWindow(new IntPtr(Item.Current.NativeWindowHandle));
 }