Beispiel #1
0
        public void Select(string item)
        {
            this.PrepareForReplay();
            int itemindex = -1;
            AutomationElementCollection alllabitem     = this._childs;
            SelectionItemPattern        labitempattern = null;

            if (item.IndexOf('#') == 0)
            {
                itemindex = Convert.ToInt16(item.Substring(1));
                if (alllabitem.Count - 1 < itemindex)
                {
                    ControlSearcher.ThrowError(ErrorType.OutRange);
                }
                else
                {
                    labitempattern = (SelectionItemPattern)alllabitem[itemindex].GetCurrentPattern(SelectionItemPattern.Pattern);
                    labitempattern.Select();
                    return;
                }
            }
            else
            {
                for (int i = 0; i < alllabitem.Count; i++)
                {
                    if (alllabitem[i].Current.Name.Trim() == item)
                    {
                        labitempattern = (SelectionItemPattern)alllabitem[i].GetCurrentPattern(SelectionItemPattern.Pattern);
                        labitempattern.Select();
                        return;
                    }
                }
            }
            ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist);
        }
 public void Check(bool value)
 {
     this.PrepareForReplay();
     try
     {
         SelectionItemPattern itempattern = (SelectionItemPattern)this._condition.AutomationElement.GetCurrentPattern(SelectionItemPattern.Pattern);
         bool v = false;
         if (value)
         {
             v = true;
         }
         else
         {
             v = false;
         }
         if (itempattern.Current.IsSelected != v)
         {
             itempattern.Select();
         }
     }
     catch
     {
         ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
     }
 }
Beispiel #3
0
        public void Select(string MenuPath)
        {
            AutomationElement curentmenuitem = _getmenuitembypath(this._condition.AutomationElement, MenuPath);

            if (curentmenuitem == null)
            {
                ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist);
            }
            else
            {
                try
                {
                    ExpandCollapsePattern mexpand = (ExpandCollapsePattern)curentmenuitem.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                    mexpand.Expand();
                }
                catch
                {
                    try
                    {
                        Point p = new Point(curentmenuitem.Current.BoundingRectangle.Left, curentmenuitem.Current.BoundingRectangle.Top);
                        KeyInput.Click(KeyInput.MouseClickType.LClick, p);
                    }
                    catch
                    {
                        ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
                    }
                }
            }
        }
        public void DBClick(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.RDClcik, handle, x, y);
                }
                else
                {
                    KeyInput.Click(KeyInput.MouseClickType.LDClick, handle, x, y);
                }
            }
            else
            {
                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.RDClcik, p);
                    }
                    else
                    {
                        KeyInput.Click(KeyInput.MouseClickType.LDClick, p);
                    }
                    return;
                }
                catch
                {
                    ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
                }
            }
        }
Beispiel #5
0
        public string GetItem(int itemindex)
        {
            AutomationElementCollection child = _lists;

            if (child.Count <= itemindex)
            {
                ControlSearcher.ThrowError(ErrorType.OutRange, "List Item index is out of range");
            }
            return(child[itemindex].Current.Name);
        }
Beispiel #6
0
        public string GetColumnName(int columnindex)
        {
            AutomationElementCollection ca = _columns;

            if (ca.Count <= columnindex)
            {
                ControlSearcher.ThrowError(ErrorType.OutRange);
            }
            return(ca[columnindex].Current.Name);
        }
Beispiel #7
0
        public string GetItem(int itemindex)
        {
            //this.PrepareForReplay();
            Open();
            try
            {
                Condition listCondtion         = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem);
                AutomationElementCollection ac = this._condition.AutomationElement.FindAll(TreeScope.Descendants, listCondtion);
                if (ac.Count - 1 < itemindex)
                {
                    ControlSearcher.ThrowError(ErrorType.OutRange);
                }
                else
                {
                    //check the name property is suit for selection value
                    if (ac.Count > 2)
                    {
                        // if all the value is the same to others, try to use the value and text pattern.
                        if (ac[0].Current.Name == ac[1].Current.Name)
                        {
                            try
                            {
                                TextPattern t = (TextPattern)ac[itemindex].GetCurrentPattern(TextPattern.Pattern);
                                if (t.DocumentRange.GetText(-1) != "")
                                {
                                    return(t.DocumentRange.GetText(-1));
                                }
                            }
                            catch
                            { }

                            try
                            {
                                ValuePattern v = (ValuePattern)ac[itemindex].GetCurrentPattern(ValuePattern.Pattern);
                                if (v.Current.Value != "")
                                {
                                    return(v.Current.Value);
                                }
                            }
                            catch
                            { }
                        }
                        return(ac[itemindex].Current.Name);
                    }
                    else
                    {
                        return(ac[itemindex].Current.Name);
                    }
                }
            }
            catch { }
            return("");
        }
Beispiel #8
0
 public void Restore()
 {
     this.PrepareForReplay();
     try
     {
         int hwnd = this._condition.AutomationElement.Current.NativeWindowHandle;
         SafeNativeMethods.ShowWindow((IntPtr)hwnd, NativeMethods.SW_RESTORE);
     }
     catch
     {
         ControlSearcher.ThrowError(ErrorType.ObjectNotExist);
     }
 }
Beispiel #9
0
        public void OpenMenu(string itemname)
        {
            AutomationElement menuitem = _getitem(itemname);

            try
            {
                ExpandCollapsePattern mexpand = (ExpandCollapsePattern)menuitem.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                mexpand.Expand();
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
            }
        }
Beispiel #10
0
        public void CollapseTreeNode(string treepath)
        {
            AutomationElement e = _openitem(this._condition.AutomationElement, treepath, false);

            try
            {
                ExpandCollapsePattern mexpand = (ExpandCollapsePattern)e.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                mexpand.Collapse();
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
            }
        }
Beispiel #11
0
        public void Press(string itemname)
        {
            AutomationElement menuitem = _getitem(itemname);

            try
            {
                UIAControlBase c = new UIAControlBase(new UIACondition(menuitem));
                c.Click(3, 3);
                return;
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
            }
        }
Beispiel #12
0
        public string ItemName(int index)
        {
            this.PrepareForReplay();
            AutomationElementCollection ac = this._allitems;

            if (ac.Count - 1 < index)
            {
                ControlSearcher.ThrowError(ErrorType.OutRange);
            }
            else
            {
                return(ac[index].Current.Name);
            }
            return("");
        }
Beispiel #13
0
        public string GetColumnName(int columnindex)
        {
            this.PrepareForReplay();
            try
            {
                AutomationElementCollection allcolumns = _getcolumns;
                if (columnindex >= allcolumns.Count)
                {
                    ControlSearcher.ThrowError(ErrorType.OutRange);
                }
                return(allcolumns[columnindex].Current.Name);
            }
            catch {}

            return("");
        }
Beispiel #14
0
        private AutomationElement _getcell(AutomationElement row, int columnindex)
        {
            int       cell          = 0x1D;
            Condition cellcondition = new PropertyCondition(LegacyIAccessiblePattern.RoleProperty, cell);
            AutomationElementCollection allelement = row.FindAll(TreeScope.Descendants, cellcondition);

            if (columnindex >= allelement.Count)
            {
                ControlSearcher.ThrowError(ErrorType.OutRange);
            }
            else
            {
                return(allelement[columnindex]);
            }
            return(null);
        }
Beispiel #15
0
        private AutomationElement _getcell(int rowindex, string columnname)
        {
            this.PrepareForReplay();
            int columnindex = -1;

            try
            {
                try
                {
                    if (columnname.IndexOf('#') == 0)
                    {
                        columnindex = Convert.ToInt16(columnname.Substring(1));
                    }
                }
                catch
                {
                    AutomationElementCollection iColumns = _getcolumns;
                    for (int i = 0; i < iColumns.Count; i++)
                    {
                        if (iColumns[i].Current.Name == columnname)
                        {
                            columnindex = i;
                        }
                    }
                }
                if (columnindex != -1)
                {
                    try
                    {
                        return(_getcell(_getrows[rowindex], columnindex));
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        ControlSearcher.ThrowError(ErrorType.OutRange);
                    }
                    //catch
                }
                else
                {
                    ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist);
                }
            }
            catch
            {
            }
            return(null);
        }
Beispiel #16
0
        private AutomationElement _getitem(string itemname)
        {
            this.PrepareForReplay();
            int itemindex = -1;

            if (itemname.IndexOf('#') == 0)
            {
                itemindex = Convert.ToInt16(itemname.Substring(1));
            }

            AutomationElementCollection itemcollection = this._allitems;
            AutomationElement           menuitem       = null;

            if (itemindex != -1)
            {
                if (itemcollection.Count - 1 < itemindex)
                {
                    ControlSearcher.ThrowError(ErrorType.OutRange);
                }
                else
                {
                    menuitem = itemcollection[itemindex];
                }
            }
            else
            {
                for (int i = 0; i < itemcollection.Count; i++)
                {
                    if (itemcollection[i].Current.Name.Trim() == itemname.Trim())
                    {
                        menuitem = itemcollection[i];
                    }
                }
            }

            if (menuitem != null)
            {
                return(menuitem);
            }
            else
            {
                ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist);
            }
            return(null);
        }
Beispiel #17
0
        public void SetItemCheckedStatus(string treepath, bool Checked)
        {
            AutomationElement e = _openitem(this._condition.AutomationElement, treepath, false);

            try
            {
                TogglePattern mexpand = (TogglePattern)e.GetCurrentPattern(TogglePattern.Pattern);
                if (Checked && mexpand.Current.ToggleState == ToggleState.Off)
                {
                    mexpand.Toggle();
                }
                else if (!Checked && mexpand.Current.ToggleState == ToggleState.On)
                {
                    mexpand.Toggle();
                }
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
            }
        }
Beispiel #18
0
        public bool GetItemCheckedStatus(string treepath)
        {
            AutomationElement e = _openitem(this._condition.AutomationElement, treepath, false);

            try
            {
                TogglePattern mexpand = (TogglePattern)e.GetCurrentPattern(TogglePattern.Pattern);
                if (mexpand.Current.ToggleState == ToggleState.On)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
            }
            return(false);
        }
Beispiel #19
0
        public new void Set(string value)
        {
            this.PrepareForReplay();
            try
            {
                RangeValuePattern v = (RangeValuePattern)this._condition.AutomationElement.GetCurrentPattern(RangeValuePattern.Pattern);
                v.SetValue(Convert.ToDouble(value));
            }
            catch
            {
            }

            try
            {
                ValuePattern v = (ValuePattern)this._condition.AutomationElement.GetCurrentPattern(ValuePattern.Pattern);
                v.SetValue(value);
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
            }
        }
Beispiel #20
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);
        }
Beispiel #21
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);
        }
        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);
            }
        }
Beispiel #23
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);
        }
        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("");
        }
Beispiel #25
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);
            }
        }