Example #1
0
 private static String getLinkText(MSHTML.IHTMLElement elem)
 {
     if (elem.tagName.Equals("A"))
     {
         if (!String.IsNullOrEmpty(elem.innerText))
         {
             return(elem.innerText.Trim());
         }
     }
     return("");
 }
        internal static List <Prop> getProperties(MSHTML.IHTMLElement elem)
        {
            List <Prop> properties = new List <Prop>();

            foreach (String attr in Attributes.attrs)
            {
                Prop property = new Prop();
                property.prop = attr;
                switch (attr)
                {
                case Attributes.id:
                    property.val = elem.id == null ? "" : elem.id.Trim();
                    break;

                case Attributes.name:
                    property.val = Util.getAttribute(elem, "name");
                    break;

                case Attributes.linktext:
                    property.val = "sample text god";
                    break;

                case Attributes.classname:
                    property.val = elem.className == null ? "" : elem.className.Trim();
                    break;

                case Attributes.css:
                    property.val = getCssPath(elem);
                    break;

                case Attributes.xpath:
                    property.val = getXpath(elem);
                    break;

                case Attributes.rxpath:
                    property.val = getRelXpath(elem);
                    break;

                case Attributes.type:
                    property.val = elem.tagName.ToLower();
                    break;

                case Attributes.shantha:
                    property.val = "hi test";
                    break;
                }
                properties.Add(property);
            }

            return(properties);
        }
Example #3
0
 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;
             }
         }
     }
 }
Example #4
0
        public int FindElementYPosition(MSHTML.IHTMLElement obj)
        {
            int curtop = 0;

            if (obj.offsetParent != null)
            {
                while (obj.offsetParent != null)
                {
                    curtop += obj.offsetTop;
                    obj     = obj.offsetParent;
                }
            }

            return(curtop);
        }
Example #5
0
        private int FindElementXPosition(MSHTML.IHTMLElement obj)
        {
            int curleft = 0;

            if (obj.offsetParent != null)
            {
                while (obj.offsetParent != null)
                {
                    curleft += obj.offsetLeft;
                    obj      = obj.offsetParent;
                }
            }

            return(curleft);
        }
Example #6
0
        void ContentClick(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("On Content Click.");

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            //遍历所有选项卡
            foreach (SHDocVw.InternetExplorer Browser in shellWindows)
            {
                if (Browser.LocationURL.Contains("www.baidu.com"))
                {
                    MSHTML.IHTMLDocument2         doc2   = (MSHTML.IHTMLDocument2)Browser.Document;
                    MSHTML.IHTMLElementCollection inputs = (MSHTML.IHTMLElementCollection)doc2.all.tags("INPUT");
                    MSHTML.HTMLInputElement       input1 = (MSHTML.HTMLInputElement)inputs.item("kw", 0);
                    input1.value = "刘德华";
                    MSHTML.IHTMLElement element2 = (MSHTML.IHTMLElement)inputs.item("su", 0);
                    element2.click();
                }
            }
        }