Beispiel #1
0
        public override bool Compare(IAttributeBag attributeBag)
        {
            ElementAttributeBag elementAttributeBag = (ElementAttributeBag)attributeBag;
            IHTMLElement        element             = elementAttributeBag.IHTMLElement;

            if (IsTextContainedIn(element.innerText))
            {
                // Get all elements and filter this for TableCells
                IHTMLTableRow          tableRowElement   = (IHTMLTableRow)element;
                IHTMLElementCollection tableCellElements = tableRowElement.cells;

                if (tableCellElements.length - 1 >= columnIndex)
                {
                    IHTMLTableCell  tableCell       = (IHTMLTableCell)tableCellElements.item(columnIndex, null);
                    ICompareElement elementComparer = comparer as ICompareElement;

                    if (elementComparer != null)
                    {
                        return(elementComparer.Compare(new TableCell(elementAttributeBag.DomContainer, tableCell)));
                    }
                    return(base.Compare(new ElementAttributeBag(elementAttributeBag.DomContainer, (IHTMLElement)tableCell)));
                }
            }

            return(false);
        }
 public IAttributeBag GetAttributeBag(DomContainer domContainer)
 {
     if (_attributeBag == null)
     {
         _attributeBag = new ElementAttributeBag(domContainer);
     }
     _attributeBag.IHTMLElement = htmlElement;
     return(_attributeBag);
 }
        private ArrayList findElementsByAttribute(ElementTag elementTag, BaseConstraint constraint, bool returnAfterFirstMatch)
        {
            // Get elements with the tagname from the page
            constraint.Reset();
            ElementAttributeBag attributeBag = new ElementAttributeBag(_domContainer);

            if (FindByExactMatchOnIdPossible(constraint))
            {
                return(FindElementById(constraint, elementTag, attributeBag, returnAfterFirstMatch, _elementCollection));
            }
            return(FindElements(constraint, elementTag, attributeBag, returnAfterFirstMatch, _elementCollection));
        }
        protected override bool DoCompare(IAttributeBag attributeBag)
        {
            Element element = null;

            ElementAttributeBag elementAttributeBag = attributeBag as ElementAttributeBag;

            if (elementAttributeBag != null)
            {
                element = elementAttributeBag.ElementTyped;
            }

            if (element == null)
            {
                element = attributeBag as Element;
            }

            if (element != null)
            {
                return(EvaluateAndOrAttributes(attributeBag, _comparer.Compare(element)));
            }

            throw new Exceptions.WatiNException("This constraint class can only be used to compare against an element");
        }
Beispiel #5
0
	    private static bool FinishedAddingChildrenThatMetTheConstraints(BaseConstraint constraint, ElementTag elementTag, ElementAttributeBag attributeBag, bool returnAfterFirstMatch, IHTMLElement element, ref ArrayList children)
	    {            
	        waitUntilElementReadyStateIsComplete(element);

	        attributeBag.IHTMLElement = element;

	        bool validElementType = true;
            if (elementTag.IsInputElement)
            {
                validElementType = elementTag.CompareInputTypes(new IEElement(element));
            }

	        if (validElementType && constraint.Compare(attributeBag))
	        {
	            children.Add(element);
	            if (returnAfterFirstMatch)
	            {
	                return true;
	            }
	        }
	        return false;
	    }
Beispiel #6
0
        private static ArrayList FindElementById(BaseConstraint constraint, ElementTag elementTag, ElementAttributeBag attributeBag, bool returnAfterFirstMatch, IElementCollection elementCollection)
	    {
            ArrayList children = new ArrayList();

	        IHTMLElement element = elementTag.GetElementById(elementCollection.Elements, ((AttributeConstraint)constraint).Value);

	        if (element != null)
	        {
	            FinishedAddingChildrenThatMetTheConstraints(constraint, elementTag, attributeBag, returnAfterFirstMatch, element, ref children);
	        }
	        return children;
	    }
Beispiel #7
0
	    public static ArrayList FindElements(BaseConstraint constraint, ElementTag elementTag, ElementAttributeBag attributeBag, bool returnAfterFirstMatch, IElementCollection elementCollection)
	    {
	        IHTMLElementCollection elements = elementTag.GetElementCollection(elementCollection.Elements);
            ArrayList children = new ArrayList();

	        if (elements != null)
	        {
	            // Loop through each element and evaluate
	            int length = elements.length;
	            for (int index = 0; index < length; index++ )
                {
                    IHTMLElement element = (IHTMLElement)elements.item(index, null);
                    if (FinishedAddingChildrenThatMetTheConstraints(constraint, elementTag, attributeBag, returnAfterFirstMatch, element, ref children))
                    {
                        return children;
                    }
                }
	        }

	        return children;
	    }
Beispiel #8
0
		private ArrayList findElementsByAttribute(ElementTag elementTag, BaseConstraint constraint, bool returnAfterFirstMatch)
		{
			// Get elements with the tagname from the page
		    constraint.Reset();
            ElementAttributeBag attributeBag = new ElementAttributeBag(_domContainer);

            if (FindByExactMatchOnIdPossible(constraint))
            {
                return FindElementById(constraint, elementTag, attributeBag, returnAfterFirstMatch, _elementCollection);
            }
            return FindElements(constraint, elementTag, attributeBag, returnAfterFirstMatch, _elementCollection);
		}
Beispiel #9
0
	    public IAttributeBag GetAttributeBag(DomContainer domContainer)
	    {
	        if (_attributeBag == null)
	        {
	            _attributeBag = new ElementAttributeBag(domContainer);
	        }
	        _attributeBag.IHTMLElement = htmlElement;
	        return _attributeBag;
	    }
        private static bool FinishedAddingChildrenThatMetTheConstraints(BaseConstraint constraint, ElementTag elementTag, ElementAttributeBag attributeBag, bool returnAfterFirstMatch, IHTMLElement element, ref ArrayList children)
        {
            waitUntilElementReadyStateIsComplete(element);

            attributeBag.IHTMLElement = element;

            bool validElementType = true;

            if (elementTag.IsInputElement)
            {
                validElementType = elementTag.CompareInputTypes(new IEElement(element));
            }

            if (validElementType && constraint.Compare(attributeBag))
            {
                children.Add(element);
                if (returnAfterFirstMatch)
                {
                    return(true);
                }
            }
            return(false);
        }
        private static ArrayList FindElementById(BaseConstraint constraint, ElementTag elementTag, ElementAttributeBag attributeBag, bool returnAfterFirstMatch, IElementCollection elementCollection)
        {
            ArrayList children = new ArrayList();

            IHTMLElement element = elementTag.GetElementById(elementCollection.Elements, ((AttributeConstraint)constraint).Value);

            if (element != null)
            {
                FinishedAddingChildrenThatMetTheConstraints(constraint, elementTag, attributeBag, returnAfterFirstMatch, element, ref children);
            }
            return(children);
        }
        public static ArrayList FindElements(BaseConstraint constraint, ElementTag elementTag, ElementAttributeBag attributeBag, bool returnAfterFirstMatch, IElementCollection elementCollection)
        {
            IHTMLElementCollection elements = elementTag.GetElementCollection(elementCollection.Elements);
            ArrayList children = new ArrayList();

            if (elements != null)
            {
                // Loop through each element and evaluate
                int length = elements.length;
                for (int index = 0; index < length; index++)
                {
                    IHTMLElement element = (IHTMLElement)elements.item(index, null);
                    if (FinishedAddingChildrenThatMetTheConstraints(constraint, elementTag, attributeBag, returnAfterFirstMatch, element, ref children))
                    {
                        return(children);
                    }
                }
            }

            return(children);
        }