コード例 #1
0
ファイル: IEElement.cs プロジェクト: owenwdx/openrpa
 public IEElement(Browser browser, MSHTML.IHTMLElement Element)
 {
     Browser    = browser;
     RawElement = Element;
     ClassName  = Element.className;
     Id         = Element.id;
     TagName    = Element.tagName.ToLower();
     Name       = "";
     try
     {
         if (!(RawElement.getAttribute("Name") is System.DBNull))
         {
             Name = (string)RawElement.getAttribute("Name");
         }
     }
     catch (Exception)
     {
     }
     if (TagName == "option")
     {
         var option = Element as MSHTML.IHTMLOptionElement;
         Name = option.text;
     }
     if (TagName == "input")
     {
         MSHTML.IHTMLInputElement inputelement = Element as MSHTML.IHTMLInputElement;
         Type = inputelement.type.ToLower();
     }
     try
     {
         MSHTML.IHTMLUniqueName id = RawElement as MSHTML.IHTMLUniqueName;
         UniqueID = id.uniqueID;
     }
     catch (Exception)
     {
     }
     IndexInParent = -1;
     if (Element.parentElement != null && !string.IsNullOrEmpty(UniqueID))
     {
         MSHTML.IHTMLElementCollection children = (MSHTML.IHTMLElementCollection)Element.parentElement.children;
         for (int i = 0; i < children.length; i++)
         {
             if (children.item(i) is MSHTML.IHTMLUniqueName id && id.uniqueID == UniqueID)
             {
                 IndexInParent = i; break;
             }
         }
     }
 }
コード例 #2
0
 public IEElement(Browser browser, MSHTML.IHTMLElement Element)
 {
     Browser    = browser;
     RawElement = Element;
     className  = Element.className;
     id         = Element.id;
     tagName    = Element.tagName.ToLower();
     Name       = "";
     if (!(RawElement.getAttribute("href") is System.DBNull))
     {
         Name = RawElement.getAttribute("Name");
     }
     if (tagName == "input")
     {
         MSHTML.IHTMLInputElement inputelement = Element as MSHTML.IHTMLInputElement;
         type = inputelement.type.ToLower();
     }
     try
     {
         MSHTML.IHTMLUniqueName id = RawElement as MSHTML.IHTMLUniqueName;
         uniqueID = id.uniqueID;
     }
     catch (Exception)
     {
     }
     IndexInParent = -1;
     if (Element.parentElement != null && !string.IsNullOrEmpty(uniqueID))
     {
         MSHTML.IHTMLElementCollection children = Element.parentElement.children;
         for (int i = 0; i < children.length; i++)
         {
             MSHTML.IHTMLUniqueName id = children.item(i) as MSHTML.IHTMLUniqueName;
             if (id != null && id.uniqueID == uniqueID)
             {
                 IndexInParent = i; break;
             }
         }
     }
 }
コード例 #3
0
        public static bool IsPlaceholder(MSHTML.IHTMLElement element, bool atomic = false)
        {
            if (element == null)
            {
                return(false);
            }

            if (!element.tagName.Equals(PlaceHolderTag, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            if (!atomic)
            {
                return(true);
            }

            var result = element.getAttribute(AtomicAttribute);

            return((result != null) && result.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase));
        }
コード例 #4
0
        private static string getNode(MSHTML.IHTMLElement node)
        {
            string nodeExpr = node.tagName.ToLower();

            if (nodeExpr == null)  // Eg. node = #text
            {
                return(null);
            }
            var ngreflectname = node.getAttribute("ng-reflect-name") as string;

            if (!string.IsNullOrEmpty(ngreflectname) && nodeExpr == "input")
            {
                nodeExpr += "[@ng-reflect-name='" + ngreflectname + "']";
                return("/" + nodeExpr);
            }
            if (node.id != "" && node.id != null)
            {
                nodeExpr += "[@id='" + node.id + "']";
                return("/" + nodeExpr);
            }
            var name = node.getAttribute("name") as string;

            if (!string.IsNullOrEmpty(name) && nodeExpr == "input")
            {
                nodeExpr += "[@name='" + name + "']";
                return("/" + nodeExpr);
            }

            // Find rank of node among its type in the parent
            int rank = 1;

            MSHTML.IHTMLDOMNode nodeDom = node as MSHTML.IHTMLDOMNode;
            MSHTML.IHTMLDOMNode psDom   = nodeDom.previousSibling;
            MSHTML.IHTMLElement ps      = psDom as MSHTML.IHTMLElement;
            while (ps != null)
            {
                if (ps.tagName == node.tagName)
                {
                    rank++;
                }
                psDom = psDom.previousSibling;
                ps    = psDom as MSHTML.IHTMLElement;
            }
            if (rank > 1)
            {
                nodeExpr += "[" + rank + "]";
            }
            else
            { // First node of its kind at this level. Are there any others?
                MSHTML.IHTMLDOMNode nsDom = nodeDom.nextSibling;
                MSHTML.IHTMLElement ns    = nsDom as MSHTML.IHTMLElement;
                while (ns != null)
                {
                    if (ns.tagName == node.tagName)
                    { // Yes, mark it as being the first one
                        nodeExpr += "[1]";
                        break;
                    }
                    nsDom = nsDom.nextSibling;
                    ns    = nsDom as MSHTML.IHTMLElement;
                }
            }
            return(nodeExpr);
        }