Пример #1
0
        internal static Element GetTypedElement(DomContainer domContainer, IHTMLElement element)
        {
            Assembly assembly = Assembly.Load("ItiN");

            Element returnElement = new ElementsContainer(domContainer, element);

            foreach (Type type in assembly.GetTypes())
            {
                if (type.IsSubclassOf(typeof(Element)))
                {
                    PropertyInfo property = type.GetProperty("ElementTags");
                    if (property != null)
                    {
                        ArrayList elementTags = (ArrayList)property.GetValue(type, null);

                        if (ElementTag.IsValidElement(element, elementTags))
                        {
                            ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(Element) });
                            if (constructor != null)
                            {
                                returnElement = (Element)constructor.Invoke(new object[] { returnElement });
                                break;
                            }
                        }
                    }
                }
            }

            return(returnElement);
        }
Пример #2
0
        private ArrayList findElementsByAttribute(ElementTag elementTag, Attribute findBy, bool returnAfterFirstMatch)
        {
            // Get elements with the tagname from the page
            ArrayList children = new ArrayList();
            IHTMLElementCollection elements = elementTag.GetElementCollection(elementCollection.Elements);

            if (elements != null)
            {
                ElementAttributeBag attributeBag = new ElementAttributeBag();

                // Loop through each element and evaluate
                foreach (IHTMLElement element in elements)
                {
                    // waitUntilElementReadyStateIsComplete(element);

                    attributeBag.IHTMLElement = element;

                    if (elementTag.Compare(element) && findBy.Compare(attributeBag))
                    {
                        children.Add(element);
                        if (returnAfterFirstMatch)
                        {
                            return(children);
                        }
                    }
                }
            }

            return(children);
        }
Пример #3
0
 /// <summary>
 /// This constructor is mainly used from within WatiN.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="elementTags">The element tags the element should match with.</param>
 public Element(Element element, ArrayList elementTags)
 {
     if (ElementTag.IsValidElement(element.htmlElement, elementTags))
     {
         init(element.domContainer, element.element, element.elementFinder);
     }
     else
     {
         throw new ArgumentException(String.Format("Expected element {0}", ElementFinder.GetExceptionMessage(elementTags)), "element");
     }
 }
Пример #4
0
        private ArrayList findElementsByAttribute(ElementTag elementTag, Attribute findBy, bool returnAfterFirstMatch)
        {
            // Get elements with the tagname from the page
            ArrayList children = new ArrayList();
            IHTMLElementCollection elements = elementTag.GetElementCollection(elementCollection.Elements);

            if (elements != null)
            {
                ElementAttributeBag attributeBag = new ElementAttributeBag();

                // Loop through each element and evaluate
                foreach (IHTMLElement element in elements)
                {
                   // waitUntilElementReadyStateIsComplete(element);

                    attributeBag.IHTMLElement = element;

                    if (elementTag.Compare(element) && findBy.Compare(attributeBag))
                    {
                        children.Add(element);
                        if (returnAfterFirstMatch)
                        {
                            return children;
                        }
                    }
                }
            }

            return children;
        }