Ejemplo n.º 1
0
        //Gets that reference other Gets (or GetList)
        private WatinElement GetInternal <TElement, TCollection>(BaseElementCollection <TElement, TCollection> elements, string selectorCode)
            where TElement : global::WatiN.Core.Element
            where TCollection : global::WatiN.Core.BaseElementCollection <TElement, TCollection>
        {
            CheckPageChanged();
            if (ElementCache.ContainsKey(selectorCode) && ElementCache[selectorCode] != null)
            {
                return(ElementCache[selectorCode]);
            }

            return(SetInCache(selectorCode, GetList(elements, selectorCode).FirstOrDefault));
        }
Ejemplo n.º 2
0
        private WatinElementCollection GetList <TElement, TCollection>(BaseElementCollection <TElement, TCollection> elements, string selectorCode, Element parent = null)
            where TElement : global::WatiN.Core.Element
            where TCollection : global::WatiN.Core.BaseElementCollection <TElement, TCollection>
        {
            if (selectorCode.StartsWith("#"))
            {
                string name = selectorCode.TrimStart('#');
                return(GetList(elements, ele => (ele.TagName ?? "").ToLower() != "form" && ((ele.Id ?? "") == name || (ele.Name ?? "") == name)));
            }
            else if (selectorCode.StartsWith("'"))
            {
                string txt = selectorCode.TrimStart('\'');
                return(GetList(elements, ele => (ele.TagName ?? "").ToLower() == "a" && (ele.Text ?? "").StartsWith(txt)));
            }
            else if (selectorCode.StartsWith("_"))
            {
                return(GetList(elements, ele => (ele.Id ?? "").EndsWith(selectorCode) || (ele.Id ?? "") == selectorCode.TrimStart('_')));
            }
            else if (selectorCode.StartsWith("."))
            {
                string cssClass = selectorCode.TrimStart('.').ToLower();
                return(GetList(elements, ele => (ele.ClassName ?? "").ToLower().Contains(cssClass)));
            }
            else if (selectorCode.StartsWith("~"))
            {
                string txt = selectorCode.TrimStart('~');
                return(GetList(elements, ele => (ele.Name ?? "").StartsWith(txt) || (ele.Name ?? "").EndsWith(txt)));
            }
            else if (selectorCode.StartsWith("="))
            {
                string[] pair = selectorCode.TrimStart('=').Split(':');
                return(GetList(elements, ele => (ele.GetAttributeValue(pair[0]) ?? "") == pair[1]));
            }
            else
            {
                List <WatinElement> eles = new List <WatinElement>();
                foreach (Element ele in elements.Filter(Find.BySelector(selectorCode)))
                {
                    if (ele != null && ele is TextField)
                    {
                        eles.Add(new WatinElement(ele, ele as TextField, this));
                    }
                    else
                    {
                        eles.Add(new WatinElement(ele, this));
                    }
                }

                return(new WatinElementCollection(eles, parent));
            }
        }
Ejemplo n.º 3
0
        //Get that does something
        private WatinElement GetInternal <TElement, TCollection>(BaseElementCollection <TElement, TCollection> ec, Func <Element, bool> check)
            where TElement : global::WatiN.Core.Element
            where TCollection : global::WatiN.Core.BaseElementCollection <TElement, TCollection>
        {
            CheckPageChanged();
            Element found = ec.Where(ele => check(ele)).FirstOrDefault();

            if (found != null && found is TextField)
            {
                return(new WatinElement(found, found as TextField, this));
            }
            else
            {
                return(new WatinElement(found, this));
            }
        }
Ejemplo n.º 4
0
        //GetList that does stuff
        private WatinElementCollection GetList <TElement, TCollection>(BaseElementCollection <TElement, TCollection> elements, Func <Element, bool> check, Element parent = null)
            where TElement : global::WatiN.Core.Element
            where TCollection : global::WatiN.Core.BaseElementCollection <TElement, TCollection>
        {
            var retval = new List <WatinElement>();
            var eles   = elements.Where(ele => check(ele)).ToList();

            foreach (Element found in eles)
            {
                if (found != null && found is TextField)
                {
                    retval.Add(new WatinElement(found, found as TextField, this));
                }
                else
                {
                    retval.Add(new WatinElement(found, this));
                }
            }

            return(new WatinElementCollection(retval, parent));
        }