Exemple #1
0
        public IWebControl FindElementBy(FindByType criteria, string textCriteria, Type type, WaitingConditionType waitCondition = WaitingConditionType.NoWait, int timeoutInSeconds = 90)
        {
            activeBrowser.RefreshDomTree();
            if (waitCondition == WaitingConditionType.NoWait)
            {
                return(FindElementBy(criteria, textCriteria, type));
            }

            IWebControl control = null;
            Element     element = null;

            if (timeoutInSeconds < 1)
            {
                timeoutInSeconds = 1;
            }

            try
            {
                switch (criteria)
                {
                case FindByType.ById:
                {
                    if (waitCondition == WaitingConditionType.UntilElementIsExists)
                    {
                        activeBrowser.Find.ById(textCriteria).Wait.ForExists(timeoutInSeconds * 1000);
                    }
                    else
                    {
                        activeBrowser.Find.ById <HtmlControl>(textCriteria).Wait.ForVisible(timeoutInSeconds * 1000);
                    }
                    element = activeBrowser.Find.ById(textCriteria);
                    break;
                }

                case FindByType.ByName:
                {
                    if (waitCondition == WaitingConditionType.UntilElementIsExists)
                    {
                        activeBrowser.Find.ByName(textCriteria).Wait.ForExists(timeoutInSeconds * 1000);
                    }
                    else
                    {
                        activeBrowser.Find.ByName <HtmlControl>(textCriteria).Wait.ForVisible(timeoutInSeconds * 1000);
                    }
                    element = activeBrowser.Find.ByName(textCriteria);
                    break;
                }

                case FindByType.ByClassName:
                {
                    if (waitCondition == WaitingConditionType.UntilElementIsExists)
                    {
                        activeBrowser.Find.ByAttributes("class=~" + textCriteria).Wait.ForExists(timeoutInSeconds * 1000);
                    }
                    else
                    {
                        activeBrowser.Find.ByAttributes <HtmlControl>("class=~" + textCriteria).Wait.ForVisible(timeoutInSeconds * 1000);
                    }
                    element = activeBrowser.Find.ByAttributes("class=~" + textCriteria);
                    break;
                }

                case FindByType.ByCssSelector:
                {
                    string[] result;
                    string[] stringSeparators = new string[] { "." };
                    result = textCriteria.Split(stringSeparators, StringSplitOptions.None);
                    activeBrowser.Find.ByExpression("class=" + result[1], "tagname=" + result[0]).Wait.ForExists(timeoutInSeconds * 1000);
                    element = activeBrowser.Find.ByExpression("class=" + result[1], "tagname=" + result[0]);
                    break;
                }

                case FindByType.ByXPath:
                {
                    if (waitCondition == WaitingConditionType.UntilElementIsExists)
                    {
                        activeBrowser.Find.ByXPath(textCriteria).Wait.ForExists(timeoutInSeconds * 1000);
                    }
                    else
                    {
                        activeBrowser.Find.ByXPath <HtmlControl>(textCriteria).Wait.ForVisible(timeoutInSeconds * 1000);
                    }

                    element = activeBrowser.Find.ByXPath(textCriteria);
                    break;
                }
                }

                if (element == null)
                {
                    throw new CriteriaNotSupportedException("Criteria " + criteria + " is not supported");
                }


                if (type == typeof(ITextBox))
                {
                    control = new TelerikTextBox(element);
                }
                else if (type == typeof(IButton))
                {
                    control = new TelerikButton(element);
                }
                else if (type == typeof(IDropDownList))
                {
                    control = new TelerikDropDownList(element);
                }
                else if (type == typeof(IInputButton))
                {
                    control = new TelerikInputButton(element);
                }
                else if (type == typeof(ILabel))
                {
                    control = new TelerikLabel(element);
                }
                else if (type == typeof(IWebControl))
                {
                    control = new TelerikBaseControl(element);
                }
                else
                {
                    throw new TypeNotSupportedException("Type " + type.ToString() + " is not supported");
                }

                return(control);
            }
            catch (TypeNotSupportedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ElementNotFoundException("No element found by textcriteria =" + textCriteria, ex);
            }
        }
Exemple #2
0
        public IWebControl FindElementBy(FindByType criteria, string textCriteria, Type type)
        {
            IWebControl control = null;
            Element     element = null;

            try
            {
                activeBrowser.RefreshDomTree();
                activeBrowser.WaitUntilReady();
                switch (criteria)
                {
                case FindByType.ById:
                {
                    element = activeBrowser.Find.ById(textCriteria);
                    break;
                }

                case FindByType.ByName:
                {
                    element = activeBrowser.Find.ByName(textCriteria);
                    break;
                }

                case FindByType.ByClassName:
                {
                    element = activeBrowser.Find.ByAttributes("class=~" + textCriteria);
                    break;
                }

                case FindByType.ByCssSelector:
                {
                    string[] result;
                    string[] stringSeparators = new string[] { "." };
                    result  = textCriteria.Split(stringSeparators, StringSplitOptions.None);
                    element = activeBrowser.Find.ByExpression("class=" + result[1], "tagname=" + result[0]);
                    break;
                }

                case FindByType.ByXPath:
                {
                    element = activeBrowser.Find.ByXPath(textCriteria);
                    break;
                }
                }

                if (element == null)
                {
                    throw new CriteriaNotSupportedException("Criteria " + criteria + " is not supported");
                }

                if (type == typeof(ITextBox))
                {
                    control = new TelerikTextBox(element);
                }
                else if (type == typeof(IButton))
                {
                    control = new TelerikButton(element);
                }
                else if (type == typeof(IDropDownList))
                {
                    control = new TelerikDropDownList(element);
                }
                else if (type == typeof(ILabel))
                {
                    control = new TelerikLabel(element);
                }
                else if (type == typeof(IInputButton))
                {
                    control = new TelerikInputButton(element);
                }
                else if (type == typeof(IWebControl))
                {
                    control = new TelerikBaseControl(element);
                }
                else
                {
                    throw new TypeNotSupportedException("Type " + type.ToString() + " is not supported");
                }

                return(control);
            }
            catch (TypeNotSupportedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ElementNotFoundException("No element found by textcriteria =" + textCriteria, ex);
            }
        }