Beispiel #1
0
        private void log(TreeNode treeNode)
        {
            List <string> log = new List <string>();

            log.Add(((IHTMLDOMNode)treeNode.Tag).nodeName);
            TreeNode pn = treeNode.Parent;

            while (pn != null)
            {
                IHTMLDOMNode n      = (IHTMLDOMNode)pn.Tag;
                string       prefix = "";
                if (n.attributes != null)
                {
                    IHTMLDOMAttribute id = n.attributes.item("id") as IHTMLDOMAttribute;
                    if (id != null && id.nodeValue != null)
                    {
                        prefix = "[" + id.nodeValue.ToString() + "]";
                    }
                }
                log.Add(n.nodeName + prefix);
                pn = pn.Parent;
            }
            log.Reverse();
            logger.Info(string.Join("/", log.ToArray()));
        }
Beispiel #2
0
        /// <summary>
        /// Tries to get the attribute name and value
        /// </summary>
        /// <param name="attribute">The attribute</param>
        /// <param name="attributeName">(out) The attribute name</param>
        /// <param name="attributeValue">(out) The attribute value</param>
        /// <returns>
        /// true, if able to get valid attribute name and value, false otherwise
        /// </returns>
        private bool TryGetAttributeValue(IHTMLDOMAttribute attribute, out string attributeName, out object attributeValue)
        {
            bool success = false;

            attributeName  = null;
            attributeValue = null;

            try
            {
                if (attribute.specified)
                {
                    attributeName  = attribute.nodeName;
                    attributeValue = attribute.nodeValue;
                    if (!string.IsNullOrWhiteSpace(attributeName) && attributeValue != null)
                    {
                        success = true;
                    }
                }
            }
            catch (NotImplementedException)
            {
                success        = false;
                attributeName  = null;
                attributeValue = null;
            }

            return(success);
        }
Beispiel #3
0
        public AttributeAdapter(object attribute, IHtmlElement element)
        {
            _attribute  = attribute as IHTMLDOMAttribute;
            _attribute2 = attribute as IHTMLDOMAttribute2;

            _element = element;

            _raw = attribute;
        }
Beispiel #4
0
    public AttributeAdapter( object attribute, IHtmlElement element )
    {
      _attribute = attribute as IHTMLDOMAttribute;
      _attribute2 = attribute as IHTMLDOMAttribute2;

      _element = element;

      _raw = attribute;
    }
Beispiel #5
0
        public string GetAttribute(string attributeName)
        {
            if (String.IsNullOrWhiteSpace(attributeName))
            {
                throw new ArgumentNullException();
            }

            IHTMLDOMAttribute domAttr = this.DomElement4.getAttributeNode(attributeName);

            if (null == domAttr)
            {
                return(String.Empty);
            }

            return(domAttr.nodeValue);
        }
Beispiel #6
0
        private void BuildAttributeDictionary(IHTMLElement htmlElem)
        {
            IHTMLDOMNode             htmlNode       = (IHTMLDOMNode)htmlElem;
            IHTMLAttributeCollection attrCollection = (IHTMLAttributeCollection)htmlNode.attributes;

            for (int i = 0; i < attrCollection.length; ++i)
            {
                Object            crntIndex     = i;
                IHTMLDOMAttribute crntAttribute = (IHTMLDOMAttribute)attrCollection.item(ref crntIndex);

                String nodeName = ((String)(crntAttribute.nodeName)).ToLower();
                if (nodeName != CatStudioConstants.HOOKED_BY_REC_ATTR)
                {
                    if ((nodeName == "src") || (nodeName == "href") ||
                        (nodeName == "id") || (nodeName == "name") ||
                        (nodeName == "class") || (nodeName == "alt") ||
                        (nodeName == "title") || (nodeName == "action") ||
                        (nodeName == "for") || (nodeName == "value"))
                    {
                        String nodeValue = crntAttribute.nodeValue as String;
                        if (nodeValue != null)
                        {
                            this.attributeMap.Add(nodeName, nodeValue);
                        }
                    }
                }
            }

            // Add "uiName" pseudo-attribute to dictionary.
            IElement twbstElem = this.browser.core.AttachToNativeElement(htmlElem);
            String   textAttr  = twbstElem.uiName.Trim(); // Remove blanks from start/end of the text.

            // Skip too long texts or empty strings.
            if (!String.IsNullOrEmpty(textAttr) && (textAttr.Length <= CatStudioConstants.MAX_TEXT_ATTR_LEN_TO_RECORD))
            {
                this.attributeMap.Add("uiname", textAttr);
            }

            // Add innerText for Watir recorder.
            String innerText = htmlElem.innerText;

            if (!String.IsNullOrEmpty(innerText) && (innerText.Length <= CatStudioConstants.MAX_TEXT_ATTR_LEN_TO_RECORD))
            {
                this.attributeMap.Add("innertext", innerText);
            }
        }