当前位置: 首页>>代码示例>>C#>>正文


C# HTMLDocument.getElementById方法代码示例

本文整理汇总了C#中HTMLDocument.getElementById方法的典型用法代码示例。如果您正苦于以下问题:C# HTMLDocument.getElementById方法的具体用法?C# HTMLDocument.getElementById怎么用?C# HTMLDocument.getElementById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTMLDocument的用法示例。


在下文中一共展示了HTMLDocument.getElementById方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: findElement

        public IHTMLElement findElement(HTMLDocument doc, IdentifierType identType, string identifier, IdentifierExpression identExp, string tagName)
        {
            IHTMLElement elem = null;
            IHTMLElementCollection elements;
            elements = null;
            switch (identType)
            {
                //If getElementByID does not work then try byExpression which is more thorough.
                case IdentifierType.Id:
                    IHTMLElement elementFound = doc.getElementById(identifier);
                    if ((elementFound != null) && (elementFound.id == identifier))
                        return elementFound;
                    else
                        return null;

                case IdentifierType.InnerHtml:
                    elements = GetElements(tagName, doc);

                    foreach (IHTMLElement el in elements)
                    {
                        if (el.innerHTML != null && el.innerHTML.Equals(identifier, StringComparison.OrdinalIgnoreCase))
                            return el;
                    }
                    break;

                case IdentifierType.InnerHtmlContains:
                    elements = GetElements(tagName, doc);

                    foreach (IHTMLElement el in elements)
                    {
                        if (el.innerHTML != null && el.innerHTML.IndexOf(identifier, 0, StringComparison.OrdinalIgnoreCase) > -1)
                            return el;
                    }
                    break;

                case IdentifierType.Expression:
                    elements = GetElements(tagName, doc);
                    return this.getElementByExp(identExp, elements);
            }

            return elem;
        }
开发者ID:dineshkummarc,项目名称:SWAT_4.1_Binaries_Source,代码行数:42,代码来源:InternetExplorer.cs

示例2: loadFiles

        public void loadFiles(XmlNode xn,HTMLDocument document)
        {
            try
            {

                /*动态加载JavaScript文件
                * 需先判断是否已经加载项目;如未加载再加入该模块
                * 
                */

                XmlNodeList jsFiles = xn.SelectNodes("js");
                foreach (XmlNode jsFile in jsFiles)
                {
                    XmlElement jsxe = (XmlElement)jsFile;

                    if (document.getElementById(jsxe.GetAttribute("keyID")) == null)
                    {                        
                        IHTMLElement script = document.createElement("script");
                        script.setAttribute("src", jsxe.InnerText, 0);
                        script.setAttribute("type", "text/javascript", 0);
                        script.setAttribute("defer", jsxe.GetAttribute("defer"), 0);
                        script.setAttribute("id", jsxe.GetAttribute("keyID"), 0); 
                        script.setAttribute("charset", "utf-8", 0);
                        IHTMLDOMNode head = (IHTMLDOMNode)document.getElementsByTagName("head").item(0, 0);
                        head.appendChild((IHTMLDOMNode)script);

                    }
                }

                /*动态加载CSS文件
                 * 需先判断是否已经加载项目;如未加载再加入该模块
                 * 
                 */

                XmlNodeList cssFiles = xn.SelectNodes("css");
                foreach (XmlNode cssFile in cssFiles)
                {
                    XmlElement cssxe = (XmlElement)cssFile;

                    if (document.getElementById(cssxe.GetAttribute("keyID")) == null)
                    {
                        
                        IHTMLElement css = document.createElement("link");
                        css.setAttribute("rel", "stylesheet", 0);
                        css.setAttribute("type", "text/css", 0);
                        css.setAttribute("href", cssxe.InnerText, 0);
                        css.setAttribute("id", cssxe.GetAttribute("keyID"), 0);
                        IHTMLDOMNode head = (IHTMLDOMNode)document.getElementsByTagName("head").item(0, 0);
                        head.appendChild((IHTMLDOMNode)css);

                        //document.createStyleSheet(cssxe.InnerText, 1);//方法二
                    }
                }
            }
            catch (Exception e)
            {
                //alert(e.Message);
                throw e;
            }

        }
开发者ID:EkaLestari,项目名称:bhohelloworld,代码行数:61,代码来源:BHO.cs

示例3: regExtension

        public void regExtension()
        {
            document = (HTMLDocument)webBrowser.Document;
            IHTMLElement e = document.getElementById("_BHO_");
            append(""+(e == null));

            if(e == null)
            {
                IHTMLElement body = document.body;
                body.insertAdjacentHTML("afterBegin", "<input id=\"_BHO_\" type=\"text\" value=\""+ DateTime.Now.ToString()+"\" />");
                append("regExtension");
                this.regExtFun();
                this.regExtJs();
            }
        }
开发者ID:mayuanxiaonong,项目名称:BHO-Csharp,代码行数:15,代码来源:BHO.cs

示例4: parseConfig

 public List<MetlConfiguration> parseConfig(MeTLConfigurationProxy server, HTMLDocument doc)
 {
     var authDataContainer = doc.getElementById("authData");
     if (authDataContainer == null)
     {
         return new List<MetlConfiguration>();
     }
     var html = authDataContainer.innerHTML;
     if (html == null)
     {
         return new List<MetlConfiguration>();
     }
     var xml = XDocument.Parse(html).Elements().ToList();
     var cc = getElementsByTag(xml, "clientConfig");
     var xmppDomain = getElementsByTag(cc, "xmppDomain").First().Value;
     var xmppUsername = getElementsByTag(cc, "xmppUsername").First().Value;
     var xmppPassword = getElementsByTag(cc, "xmppPassword").First().Value;
     var imageUrl = getElementsByTag(cc, "imageUrl").First().Value;
     return new List<MetlConfiguration>
     {
         new MetlConfiguration(server.name,server.imageUrl.ToString(),xmppDomain,xmppUsername,xmppPassword,server.host)
     };
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:23,代码来源:MeTLConfiguration.cs

示例5: OnDocumentComplete

        public void OnDocumentComplete(object pDisp, ref object URL)
        {
            /*
             * Проверка по адресу
             */
            string url = URL.ToString();
            bool matched = false;
            foreach (Regex reg in regulars)
            {
                if (reg.Match(url).Success)
                {
                    matched = true;
                    break;
                }
            };
            if (!matched)
            {
                return;
            }

            document = (HTMLDocument)webBrowser.Document;
            /*
             * скрипт уже подключён
             */
            if (document.getElementById(scriptElementId) != null)
            {
                return;
            };

            // создаем скрипт
            string source = vkpatch.Properties.Resources.vkpatch.ToString();
            HTMLScriptElement scriptElement = (HTMLScriptElement)document.createElement("script");
            scriptElement.text = source;
            scriptElement.id = "vkpatch";

            // выполняем инъекцию в head
            IHTMLElementCollection heads = document.getElementsByTagName("head");
            foreach (HTMLHeadElement head in heads)
            {
                head.appendChild((IHTMLDOMNode) scriptElement);
                break;
            }
        }
开发者ID:dolphinmeow,项目名称:vkpatch,代码行数:43,代码来源:BHO.cs

示例6: FindElement

        IHTMLElement FindElement(string xPath, HTMLDocument doc)
        {
            IHTMLElement theElement = null;

            try
            {
                string[] tmp = xPath.Split(new string[] { "##" }, StringSplitOptions.None);

                string elementAttributes = tmp[1];
                string[] attributes = elementAttributes.Split(new string[] { ";" }, StringSplitOptions.None);
                string attributeId = attributes[0].Replace(@"id=", "");
                string attributeName = attributes[1].Replace(@"name=", "");
                string attributeClass = attributes[2].Replace(@"class=", "");

                string[] xPathParts = tmp[0].Split('/');
                string elementTagName = xPathParts[xPathParts.Length - 1];
                if (elementTagName.Contains("["))
                {
                    elementTagName = elementTagName.Split('[')[0];
                }

                // try in first place the id (if it's unique)
                theElement = doc.getElementById(attributeId);
                if (theElement != null && !String.IsNullOrEmpty(attributeId))
                {
                    int c = 0;
                    IHTMLElementCollection possibleElements = doc.getElementsByTagName(elementTagName);
                    foreach (IHTMLElement possibleElement in possibleElements)
                    {
                        if (possibleElement.id == attributeId)
                        {
                            c++;
                        }
                    }

                    if (c > 1)
                    {
                        theElement = null;
                    }
                }

                if (theElement == null && !String.IsNullOrEmpty(attributeName))
                {
                    IHTMLElementCollection possibleElements = doc.getElementsByName(attributeName);
                    if (possibleElements.length == 1)
                    {
                        theElement = (IHTMLElement)possibleElements.item(null, 0);
                    }
                }

                // try next, the exact xpath
                try
                {
                    if (theElement == null)
                    {
                        IHTMLElementCollection possibleElements = doc.getElementsByTagName(elementTagName);
                        foreach (IHTMLElement possibleElement in possibleElements)
                        {
                            string possibleXPath = "";
                            try
                            {
                                possibleXPath = Utils.FindXPath(possibleElement);
                                //Utils.l(possibleXPath);
                            }
                            catch (Exception e) {
                                //Utils.l(e);
                            }

                            if (possibleXPath == xPath)
                            {
                                theElement = possibleElement;
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utils.l(ex);
                }

                try
                {
                    // next, try the path skipping attributes
                    if (theElement == null)
                    {
                        string cleanXPath = tmp[0];
                        IHTMLElementCollection possibleElements = doc.getElementsByTagName(elementTagName);
                        foreach (IHTMLElement possibleElement in possibleElements)
                        {
                            if (possibleElement.tagName == "INPUT") {
                                IHTMLInputElement tmpInput = (IHTMLInputElement)possibleElement;
                                if (tmpInput.type == "hidden" || tmpInput.type == "text" || tmpInput.type == "password")
                                {
                                    continue;
                                }
                            }

                            string possibleXPath = Utils.FindXPath(possibleElement);
                            string[] possibleTmp = possibleXPath.Split(new string[] { "##" }, StringSplitOptions.None);
//.........这里部分代码省略.........
开发者ID:mradosta,项目名称:thousandpass,代码行数:101,代码来源:_1000Pass_BHO.cs

示例7: GetElementByID

        // Recursive implementation of the above function.
        //
        private IHTMLElement GetElementByID(string id, HTMLDocument parentDoc)
        {
            string[] frameTags = new string[] {"FRAME", "IFRAME"};
            IHTMLElement element = null;

            // Try getting element directly from doc...
            //
            element = parentDoc.getElementById(id);

            // Otherwise, search all current frames.
            //
            foreach(string tag in frameTags)
            {
                if (element == null)
                {
                    FramesCollection frames = parentDoc.frames;

                    int i = 0;
                    while (i < frames.length && element == null)
                    {
                        // Get document from frame
                        //
                        object refID = i;
                        HTMLWindow2 frame = (HTMLWindow2)frames.item(ref refID);
                        HTMLDocument currentDocument = (HTMLDocument)frame.document;

                        // Wait for document to load
                        //
                        // TODO: Handle frames which can't access readyState
                        while (!currentDocument.readyState.Equals("complete")) { Thread.Sleep(500); }

                        // Get element
                        //
                        element = currentDocument.getElementById(id);

                        // Release COM objects as appropriate
                        //
                        Marshal.ReleaseComObject(frame);

                        // Check sub-frames and release appropriately
                        //
                        if (element == null)
                        {
                            // Check child frames
                            //
                            element = this.GetElementByID(id, currentDocument);

                            if (element == null)
                            {
                                Marshal.ReleaseComObject(currentDocument);
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }

                        i++;
                    }

                    Marshal.ReleaseComObject(frames);
                }
            }

            return element;
        }
开发者ID:urbaneinnovation,项目名称:Ice,代码行数:72,代码来源:InternetExplorerApplication.cs


注:本文中的HTMLDocument.getElementById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。