예제 #1
0
        public IUIAList UIAList(string conditions, string conditions1 = "", string conditions2 = "", string conditions3 = "", string conditions4 = "", string conditions5 = "", string conditions6 = "", string conditions7 = "", string conditions8 = "", string conditions9 = "")
        {
            UIACondition cdition = ControlSearcher.GetCondition(_condition, ControlType.List, conditions, conditions1, conditions2, conditions3, conditions4, conditions5, conditions6, conditions7, conditions8, conditions9);

            return((UIAList)UIACommonMethods.ObjectCreator(cdition));
        }
예제 #2
0
        private AutomationElement _openitem(AutomationElement parentitem, string treepath, bool openlastone = false)
        {
            string[] path = treepath.Split(';');
            if (parentitem == null)
            {
                ControlSearcher.ThrowError(ErrorType.ObjectIsOutOfScreen, treepath);
                return(null);
            }
            AutomationElementCollection allitems           = this._items(parentitem);
            AutomationElement           treeNodeItemObject = null;

            if (path.Length != 0)
            {
                if (path[0].IndexOf('#') == 0)
                {
                    int treenodeindex = -1;
                    treenodeindex = Convert.ToInt16(path[0].Substring(1));
                    if (allitems.Count - 1 < treenodeindex)
                    {
                        ControlSearcher.ThrowError(ErrorType.OutRange, "Value: " + treenodeindex.ToString());
                    }
                    else
                    {
                        treeNodeItemObject = allitems[treenodeindex];
                    }
                }
                else
                {
                    for (int i = 0; i < allitems.Count; i++)
                    {
                        if (allitems[i].Current.Name.Trim() == path[0].Trim())
                        {
                            treeNodeItemObject = allitems[i];
                        }
                    }
                }
                if (treeNodeItemObject == null)
                {
                    ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist, "Value: " + path[0].ToString());
                }
                else
                {
                    if ((openlastone && path.Length == 1) || (path.Length > 1))
                    {
                        try
                        {
                            ExpandCollapsePattern mexpand = (ExpandCollapsePattern)treeNodeItemObject.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                            mexpand.Expand();
                        }
                        catch
                        {
                            try
                            {
                                Point p = new Point((int)treeNodeItemObject.Current.BoundingRectangle.Left, (int)treeNodeItemObject.Current.BoundingRectangle.Top);
                                KeyInput.Click(KeyInput.MouseClickType.LClick, p);
                            }
                            catch
                            {
                                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation, "Value: " + path[0].ToString());
                            }
                        }

                        if (path.Length > 1)
                        {
                            treepath = treepath.Substring(path[0].Length + 1);
                            return(_openitem(treeNodeItemObject, treepath, openlastone));
                        }
                        else
                        {
                            return(treeNodeItemObject);
                        }
                    }
                    else
                    {
                        return(treeNodeItemObject);
                    }
                }
            }
            return(null);
        }
예제 #3
0
        private AutomationElement _getmenuitembypath(AutomationElement parentitem, string menupath, bool openlastone = false)
        {
            string[] path = menupath.Split(';');
            if (parentitem == null)
            {
                ControlSearcher.ThrowError(ErrorType.ObjectIsOutOfScreen, menupath);
                return(null);
            }
            AutomationElementCollection allItems       = this._getchilds(parentitem);
            AutomationElement           curentMenuItem = null;

            if (path.Length != 0)
            {
                if (path[0].IndexOf('#') == 0)
                {
                    int menuindex = -1;
                    menuindex = Convert.ToInt16(path[0].Substring(1));
                    if (allItems.Count - 1 < menuindex)
                    {
                        ControlSearcher.ThrowError(ErrorType.OutRange, "Value: " + menuindex.ToString());
                    }
                    else
                    {
                        curentMenuItem = allItems[menuindex];
                    }
                }
                else
                {
                    for (int i = 0; i < allItems.Count; i++)
                    {
                        if (allItems[i].Current.Name.Trim() == path[0].Trim())
                        {
                            curentMenuItem = allItems[i];
                        }
                    }
                }
                if (curentMenuItem == null)
                {
                    ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist, "Value: " + path[0].ToString());
                }
                else
                {
                    if ((openlastone && path.Length == 1) || (path.Length > 1))
                    {
                        try
                        {
                            ExpandCollapsePattern mexpand = (ExpandCollapsePattern)curentMenuItem.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                            mexpand.Expand();
                            Thread.Sleep(300);
                            mexpand.Expand();
                            Thread.Sleep(300);

                            if (mexpand.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                            {
                                try
                                {
                                    Point p = new Point((int)curentMenuItem.Current.BoundingRectangle.Left, (int)curentMenuItem.Current.BoundingRectangle.Top);
                                    KeyInput.Click(KeyInput.MouseClickType.LClick, p);
                                }
                                catch
                                {
                                    ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation, "Value: " + path[0].ToString());
                                }
                            }
                        }
                        catch
                        {
                            try
                            {
                                Point p = new Point((int)curentMenuItem.Current.BoundingRectangle.Left, (int)curentMenuItem.Current.BoundingRectangle.Top);
                                KeyInput.Click(KeyInput.MouseClickType.LClick, p);
                            }
                            catch
                            {
                                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation, "Value: " + path[0].ToString());
                            }
                        }

                        if (path.Length > 1)
                        {
                            menupath = menupath.Substring(path[0].Length + 1);
                            return(_getmenuitembypath(curentMenuItem, menupath, openlastone));
                        }
                        else
                        {
                            return(curentMenuItem);
                        }
                    }
                    else
                    {
                        return(curentMenuItem);
                    }
                }
            }
            return(null);
        }
예제 #4
0
        public IUIARadioButton UIARadiobutton(string conditions, string conditions1 = "", string conditions2 = "", string conditions3 = "", string conditions4 = "", string conditions5 = "", string conditions6 = "", string conditions7 = "", string conditions8 = "", string conditions9 = "")
        {
            UIACondition cdition = ControlSearcher.GetCondition(this._condition, ControlType.RadioButton, conditions, conditions1, conditions2, conditions3, conditions4, conditions5, conditions6, conditions7, conditions8, conditions9);

            return((UIARadioButton)UIACommonMethods.ObjectCreator(cdition));
        }
예제 #5
0
        public string GetColumnItemValue(string item, string column)
        {
            AutomationElementCollection ca = _columns;
            AutomationElementCollection ia = _lists;

            int itemindex = -1, columnindex = -1;

            if (item.IndexOf('#') == 0)
            {
                itemindex = Convert.ToInt16(item.Substring(1));
                if (ia.Count <= itemindex)
                {
                    ControlSearcher.ThrowError(ErrorType.OutRange, "List Item index is out of range");
                }
            }
            else
            {
                for (int i = 0; i < ia.Count; i++)
                {
                    if (ia[i].Current.Name.Trim() == item.Trim())
                    {
                        itemindex = i;
                    }
                }
            }
            if (column.IndexOf('#') == 0)
            {
                columnindex = Convert.ToInt16(column.Substring(1));
                if (ca.Count <= columnindex)
                {
                    ControlSearcher.ThrowError(ErrorType.OutRange, "Column Item index is not in the list");
                }
            }
            else
            {
                for (int j = 0; j < ca.Count; j++)
                {
                    if (ca[j].Current.Name.Trim() == column.Trim())
                    {
                        columnindex = j;
                    }
                }
            }

            if (itemindex == -1)
            {
                ControlSearcher.ThrowError(ErrorType.OutRange, "List Item is not in the list");
            }
            if (columnindex == -1)
            {
                ControlSearcher.ThrowError(ErrorType.OutRange, "Column Item is not in the header");
            }

            AutomationElement           lelement = ia[itemindex];
            AutomationElementCollection childitem = lelement.FindAll(TreeScope.Children, TreeWalker.ControlViewWalker.Condition);

            if (childitem.Count <= columnindex)
            {
                ControlSearcher.ThrowError(ErrorType.OutRange, "Column Item index is not in the list");
            }
            try
            {
                return(((ValuePattern)childitem[columnindex].GetCurrentPattern(ValuePattern.Pattern)).Current.Value);
            }
            catch
            { }

            try
            {
                return(((TextPattern)childitem[columnindex].GetCurrentPattern(TextPattern.Pattern)).DocumentRange.GetText(-1));
            }
            catch
            { }

            return(childitem[columnindex].Current.Name);
        }
예제 #6
0
        public IUIAScrollBar UIAScrollbar(string conditions, string conditions1 = "", string conditions2 = "", string conditions3 = "", string conditions4 = "", string conditions5 = "", string conditions6 = "", string conditions7 = "", string conditions8 = "", string conditions9 = "")
        {
            UIACondition cdition = ControlSearcher.GetCondition(this._condition, ControlType.ScrollBar, conditions, conditions1, conditions2, conditions3, conditions4, conditions5, conditions6, conditions7, conditions8, conditions9);

            return((UIAScrollBar)UIACommonMethods.ObjectCreator(cdition));
        }
예제 #7
0
        public void Select(string ItemName)
        {
            this.Open();
            int itemindex = -1;

            if (ItemName.IndexOf('#') == 0)
            {
                itemindex = Convert.ToInt16(ItemName.Substring(1));
            }
            Condition listCondtion               = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem);
            AutomationElementCollection ac       = this._condition.AutomationElement.FindAll(TreeScope.Descendants, listCondtion);
            AutomationElement           listitem = null;

            if (itemindex != -1)
            {
                if (ac.Count - 1 < itemindex)
                {
                    ControlSearcher.ThrowError(ErrorType.OutRange);
                }
                else
                {
                    listitem = ac[itemindex];
                }
            }
            else
            {
                for (int i = 0; i < ac.Count; i++)
                {
                    if (ac[i].Current.Name.Trim() == ItemName.Trim())
                    {
                        listitem = ac[i];
                    }
                }
                if (listitem == null)
                {
                    for (int i = 0; i < ac.Count; i++)
                    {
                        TextPattern t = (TextPattern)ac[i].GetCurrentPattern(TextPattern.Pattern);
                        if (t.DocumentRange.GetText(-1).Trim() == ItemName.Trim())
                        {
                            listitem = ac[i];
                        }
                    }
                }

                if (listitem == null)
                {
                    for (int i = 0; i < ac.Count; i++)
                    {
                        ValuePattern v = (ValuePattern)ac[i].GetCurrentPattern(ValuePattern.Pattern);
                        if (v.Current.Value.Trim() == ItemName.Trim())
                        {
                            listitem = ac[i];
                        }
                    }
                }
            }

            if (listitem != null)
            {
                try
                {
                    SelectionItemPattern itempattern = (SelectionItemPattern)listitem.GetCurrentPattern(SelectionItemPattern.Pattern);
                    itempattern.Select();
                    if (_checkvalue(listitem.Current.Name))
                    {
                        return;
                    }
                }
                catch
                {
                }

                try
                {
                    if (listitem.Current.NativeWindowHandle != 0)
                    {
                        KeyInput.Click(KeyInput.MouseClickType.LClick, listitem.Current.NativeWindowHandle);
                        if (_checkvalue(listitem.Current.Name))
                        {
                            return;
                        }
                    }
                }
                catch
                { }

                try
                {
                    Point p = new Point((int)listitem.Current.BoundingRectangle.Left, (int)listitem.Current.BoundingRectangle.Top);
                    KeyInput.Click(KeyInput.MouseClickType.LClick, p);
                    if (_checkvalue(listitem.Current.Name))
                    {
                        return;
                    }
                }
                catch
                { }
                //ControlSearcher.ThrowError(ErrorType.CannotperforthisOperation);
            }
            else
            {
                ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist);
            }
        }
예제 #8
0
        protected void PrepareForReplay()
        {
            if (!this.Exist(2))
            {
                ControlSearcher.ThrowError(ErrorType.ObjectNotExist);
            }
            if (_condition.AutomationElement.Current.HasKeyboardFocus)
            {
                return;
            }

            AutomationElement rootwindow = UIAUtility.GetRootWindow(_condition.AutomationElement);

            if (rootwindow == null)
            {
                rootwindow = _condition.AutomationElement;
            }
            int rootWindowHandle = (int)rootwindow.Current.NativeWindowHandle;

            try
            {
                Point p;
                p = rootwindow.GetClickablePoint();
                SafeNativeMethods.SetForegroundWindow((IntPtr)rootWindowHandle);
                return;
            }
            catch
            {
            }

            //if Object can not get the clickble point, will try to get the parent.
            //try to make the root window to visible
            try
            {
                SafeNativeMethods.SetForegroundWindow((IntPtr)rootWindowHandle);
                Point p;
                p = rootwindow.GetClickablePoint();
                // if the window is visible now, start to check the object is out of screen.
                if (!_condition.AutomationElement.Current.IsOffscreen)
                {
                    ControlSearcher.ThrowError(ErrorType.ObjectIsOutOfScreen);
                }
                else
                {
                    return;
                }
            }
            catch
            {
            }
            // Window is not visible, start to make it visible
            SafeNativeMethods.ShowWindow((IntPtr)rootWindowHandle, 4);
            SafeNativeMethods.SetForegroundWindow((IntPtr)rootWindowHandle);

            //Check again
            try
            {
                string value = _condition.AutomationElement.Current.ClassName;
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
            }

            if (_condition.AutomationElement.Current.IsOffscreen)
            {
                return;
            }
            else
            {
                ControlSearcher.ThrowError(ErrorType.ObjectIsOutOfScreen);
            }
        }
예제 #9
0
        public void Click(int x = 0, int y = 0, int mousekey = 1)
        {
            PrepareForReplay();
            int handle = 0;

            try
            {
                handle = (int)_condition.AutomationElement.Current.NativeWindowHandle;
            }
            catch { }

            if (x == 0 && y == 0)
            {
                try
                {
                    Rect tr_point = _condition.AutomationElement.Current.BoundingRectangle;
                    x = (int)(tr_point.Right - tr_point.Left) / 2;
                    y = (int)(tr_point.Bottom - tr_point.Top) / 2;
                }
                catch { }
            }

            if (handle != 0)
            {
                if (mousekey == 2)
                {
                    KeyInput.Click(KeyInput.MouseClickType.RClick, handle, x, y);
                }
                else
                {
                    KeyInput.Click(KeyInput.MouseClickType.LClick, handle, x, y);
                }
            }
            else
            {
                //using Point to click
                try
                {
                    Point p  = new Point();
                    Rect  tr = _condition.AutomationElement.Current.BoundingRectangle;
                    p.X = (int)tr.Left + x;
                    p.Y = (int)tr.Top + y;
                    if (mousekey == 2)
                    {
                        KeyInput.Click(KeyInput.MouseClickType.RClick, p);
                    }
                    else
                    {
                        KeyInput.Click(KeyInput.MouseClickType.LClick, p);
                    }
                    return;
                }
                catch { }

                try
                {
                    ((InvokePattern)_condition.AutomationElement.GetCurrentPattern(InvokePattern.Pattern)).Invoke();
                }
                catch
                {
                    ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
                }
            }
        }
예제 #10
0
        public string GetRoProperty(string propertyname)
        {
            PrepareForReplay();
            try
            {
                switch (propertyname.ToLower().Trim())
                {
                case "title":
                    return((string)_condition.AutomationElement.Current.Name);

                case "name":
                    return((string)_condition.AutomationElement.Current.Name);

                case "text":
                    return(this.Text);

                case "hwnd":
                    return(_condition.AutomationElement.Current.NativeWindowHandle.ToString());

                case "handle":
                    return(_condition.AutomationElement.Current.NativeWindowHandle.ToString());

                case "x":
                    return(_condition.AutomationElement.Current.BoundingRectangle.Left.ToString());

                case "y":
                    return(_condition.AutomationElement.Current.BoundingRectangle.Top.ToString());

                case "height":
                    return((_condition.AutomationElement.Current.BoundingRectangle.Bottom - _condition.AutomationElement.Current.BoundingRectangle.Top).ToString());

                case "width":
                    return((_condition.AutomationElement.Current.BoundingRectangle.Right - _condition.AutomationElement.Current.BoundingRectangle.Left).ToString());

                case "enabled":
                    if (_condition.AutomationElement.Current.IsEnabled)
                    {
                        return("true");
                    }
                    else
                    {
                        return("false");
                    }

                case "focused":
                    if (_condition.AutomationElement.Current.HasKeyboardFocus)
                    {
                        return("true");
                    }
                    else
                    {
                        return("false");
                    }

                case "helptext":
                    return(_condition.AutomationElement.Current.HelpText);

                case "value":
                    return(this.Value);

                case "labeledtext":
                    if (_condition.AutomationElement.Current.LabeledBy != null)
                    {
                        return(_condition.AutomationElement.Current.LabeledBy.Current.Name);
                    }
                    else
                    {
                        return("");
                    }

                case "processid":
                    return(_condition.AutomationElement.Current.ProcessId.ToString());
                }
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation, "Object doese not support this property");
            }
            return("");
        }