Exemple #1
0
        public static int GetLinkElementIndex(mshtml.IHTMLDocument2 doc, mshtml.IHTMLElement ele, string itemName, string tagStr)
        {
            mshtml.IHTMLElementCollection links;
            int        num       = 0;
            bool       flag      = false;
            ElementTag outerText = ElementTag.outerText;

            if (!string.IsNullOrEmpty(tagStr))
            {
                outerText = (ElementTag)WindowUtil.StringToInt(tagStr);
            }
            if (outerText != ElementTag.src)
            {
                links = doc.links;
                if (links == null)
                {
                    goto Label_00EA;
                }
                foreach (mshtml.IHTMLElement element2 in links)
                {
                    if (IsElementMatch(element2, outerText, itemName, ""))
                    {
                        if (ele == element2)
                        {
                            flag = true;
                            break;
                        }
                        num++;
                    }
                }
            }
            else
            {
                links = doc.images;
                if (links != null)
                {
                    foreach (mshtml.IHTMLElement element in links)
                    {
                        if (IsElementMatch(element, outerText, itemName, ""))
                        {
                            if (ele == element)
                            {
                                flag = true;
                                break;
                            }
                            num++;
                        }
                    }
                    Marshal.ReleaseComObject(links);
                }
                goto Label_00EA;
            }
            Marshal.ReleaseComObject(links);
Label_00EA:
            if (!flag)
            {
                num = 0;
            }
            return(num);
        }
Exemple #2
0
        private void PraiseFriend()
        {
            try
            {
                mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass;

                for (int i = 0; i < htmlDoc.frames.length; ++i)
                {
                    object index = i;
                    mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2;

                    IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow);

                    mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("a");
                    IEnumerator tagie = tagls.GetEnumerator();
                    while (tagie.MoveNext())
                    {
                        mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current;
                        if (element.className == "item qz_like_btn_v3")
                        {
                            if (element.innerText != null && !element.innerText.Contains("取消赞"))
                            {
                                element.click();
                                praisedMap.Add(curQQ);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
        }
Exemple #3
0
        public static String Search(string name)
        {
            buffer1 = new mshtml.HTMLDocument();
            buffer2 = (mshtml.IHTMLDocument2)buffer1;
            Console.WriteLine("Downloading search page for: {0}", name);
            string Data = Storage.wc.DownloadString($"https://vidstreaming.io/search.html?keyword={name}");

            buffer2.write(Data); // Write all the data to buffer1 so that we can enumerate it.
            mshtml.IHTMLElementCollection collection;
            Console.WriteLine("Searching for video-block");
            collection = buffer1.getElementsByTagName("li"); //Get all collections with the <li> tag.
            foreach (mshtml.IHTMLElement obj in collection)
            {
                if (obj.className == "video-block " || obj.className == "video-block click-hover") //if the element has a classname of "video-block " then we are dealing with a show.
                {
                    Console.WriteLine("Found video-block!");
                    node = obj; // set node to object.
                    break;      // escape the foreach loop.
                }
            }
            Expressions.vidStreamRegex = new Regex(Expressions.searchVideoRegex); // Don't say anything about parsing html with REGEX. This is a better than importing another library for this case.
            if (node == null)
            {
                return("E");
            }
            Match m = Expressions.vidStreamRegex.Match(node.innerHTML);

            return(m.Groups.Count >= 1 ? "https://vidstreaming.io" + m.Groups[1].Value : "E");
        }
Exemple #4
0
 //开始说话
 private void CommentFriend()
 {
     try
     {
         commentTag = getCommented();
         if (commentTag != null)
         {
             if (commentStep1(commentTag))
             {
                 if (commentStep2(commentTag))
                 {
                     if (commentStep3ex(commentTag))
                     {
                         curstepidx = 2;
                     }
                 }
             }
         }
         else
         {
             curstepidx = 999;
             LogFileEx.LogRow row = new LogFileEx.LogRow();
             row.add(curQQ);
             row.add("失败:没有可评论的位置获取无法访问空间");
             LogFileEx.add("Comment.txt", row);
             father.updateFailText(false);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("*********************************************************");
         Console.WriteLine(ex.ToString());
         Console.WriteLine("*********************************************************");
     }
 }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="element"></param>
        /// <param name="Finder">优先finder设置</param>
        public void SetFindMethod(IHTMLElement element, FindAttribute Finder)
        {
            int count = 0;

            if (Finder != null)
            {
                FindMechanism.Add(Finder);
                count = GetElementCount(element.tagName);
                if (count > 1)
                {
                    FindMechanism.Clear();
                }
                else
                {
                    SetFrameList(element);
                    ElementType = TagStringToElementType(element);
                    return;
                }
            }
            Finder = GetFinder(element, FindMethods.CssSelector);
            FindMechanism.Add(Finder);
            mshtml.IHTMLDOMNode node = element as mshtml.IHTMLDOMNode;
            count = GetElementCount(node.nodeName);
            //不支持CssSelector,试用xpath定位
            if (count == -1)
            {
                FindMechanism.Clear();
                Finder = GetFinder(element, FindMethods.XPath);
                FindMechanism.Add(Finder);
            }
            SetFrameList(element);
            ElementType = TagStringToElementType(element);
        }
Exemple #6
0
        //获取编辑框已打开
        private bool hascommentOpened(mshtml.IHTMLElement commentTag)
        {
            mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass;
            for (int i = 0; i < htmlDoc.frames.length; ++i)
            {
                object index = i;
                mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2;

                IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow);

                mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("div");
                IEnumerator tagie = tagls.GetEnumerator();
                while (tagie.MoveNext())
                {
                    mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current;
                    if (commentTag == element && element.className == "mod-comments")
                    {
                        mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.all;
                        IEnumerator cusers = childrenCol.GetEnumerator();
                        while (cusers.MoveNext())
                        {
                            mshtml.IHTMLElement element1 = (mshtml.IHTMLElement)cusers.Current;
                            if (element1.className == "comment-box-wrap")
                            {
                                return(true);
                            }
                        }
                        return(false);
                    }
                }
            }
            return(false);
        }
Exemple #7
0
        public string GetMeta(string name)
        {
            var cc = hostBrowser.GetElementsByTagName(true, "META");

            mshtml.IHTMLElement el = cc.item(name, 0) as IHTMLElement;
            return(el.getAttribute("content") as string);
        }
Exemple #8
0
        public void WebBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            //throw new NotImplementedException();
            mshtml.HTMLDocument           doc  = webBrowser.Document as mshtml.HTMLDocument;
            mshtml.IHTMLElementCollection coll = (mshtml.IHTMLElementCollection)(doc.getElementsByTagName("button"));
            mshtml.IHTMLElement           coll_id_start_explorer = (mshtml.IHTMLElement)(doc.getElementById("id_start_explorer"));
            mshtml.IHTMLElement           coll_id_start_dialog   = (mshtml.IHTMLElement)(doc.getElementById("id_start_dialog"));

            // https://codevomit.wordpress.com/2015/06/15/wpf-webbrowser-control-part-2/

            /*
             * foreach (mshtml.IHTMLElement obj in coll)
             * {
             *  HTMLButtonElementEvents_Event htmlButtonEvent = obj as HTMLButtonElementEvents_Event;
             *  htmlButtonEvent.onclick += clickElementHandler;
             * }
             * //*/

            if (coll_id_start_dialog != null)
            {
                HTMLButtonElementEvents_Event htmlButtonEvent = coll_id_start_dialog as HTMLButtonElementEvents_Event;
                htmlButtonEvent.onclick += start_dialog;
            }
            if (coll_id_start_explorer != null)
            {
                HTMLButtonElementEvents_Event htmlButtonEvent = coll_id_start_explorer as HTMLButtonElementEvents_Event;
                htmlButtonEvent.onclick += start_explorer;
            }
        }
Exemple #9
0
        public override void Perform()
        {
            //验证码获得焦点后,隐藏的验证码图片才显示出来
            if (IsHide)
            {
                //触发验证码显示
                if (ActionValidateCode != null)
                {
                    ActionValidateCode.GetElement().Focus();
                    Thread.Sleep(500);
                    Application.DoEvents();
                }
            }

            Element element = GetElement();
            //element.WaitUntilExists();
            var nativeElement = element.NativeElement as IEElement;

            mshtml.IHTMLElement el = nativeElement.AsHtmlElement as mshtml.IHTMLElement;
            el.scrollIntoView();
            ShowDialog((IHTMLElement)el);
            //if (imgId == null) {
            //    webBrowser.DrawThumb((IHTMLElement)nativeElement.AsHtmlElement, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            //}
        }
Exemple #10
0
        public static mshtml.IHTMLElement GetInputElement(mshtml.IHTMLDocument2 doc, string itemName, string tagStr, string indexStr)
        {
            mshtml.IHTMLElementCollection o       = (mshtml.IHTMLElementCollection)doc.all.tags("input");
            mshtml.IHTMLElement           element = null;
            ElementTag iD   = ElementTag.ID;
            int        num  = 0;
            int        num2 = 0;

            if (!string.IsNullOrEmpty(indexStr))
            {
                num = WindowUtil.StringToInt(indexStr);
            }
            if ((tagStr != string.Empty) && (tagStr != ""))
            {
                iD = (ElementTag)WindowUtil.StringToInt(tagStr);
            }
            foreach (mshtml.IHTMLElement element2 in o)
            {
                if (IsElementMatch(element2, iD, itemName, ""))
                {
                    if (num2 == num)
                    {
                        element = element2;
                        break;
                    }
                    num2++;
                }
            }
            if (o != null)
            {
                Marshal.ReleaseComObject(o);
            }
            return(element);
        }
Exemple #11
0
        public static bool ClickCheckedRect(IntPtr hwnd, mshtml.IHTMLDocument2 doc, string itemName, string tagStr, string indexStr, ref bool isClick, ref Point fakeMousePoint, ClickEvent clickEvent)
        {
            mshtml.IHTMLElement elem = GetCheckedElement(doc, itemName, tagStr, indexStr);
            bool flag = false;

            if (elem != null)
            {
                flag = true;
                Rectangle elementRect = GetElementRect(doc.body, elem);
                isClick = false;
                if ((elementRect.Width > 0) && (elementRect.Height > 0))
                {
                    Random random = new Random();
                    int    num    = random.Next(elementRect.Width);
                    int    num2   = random.Next(elementRect.Height);
                    SetMousePoint(hwnd, ref fakeMousePoint, elementRect.X + num, elementRect.Y + num2, doc);
                    isClick = isClickElement(hwnd, doc, elem, elementRect.X + num, elementRect.Y + num2, clickEvent);
                }
            }
            if (elem != null)
            {
                Marshal.ReleaseComObject(elem);
            }
            return(flag);
        }
        public string GetElementXPath(mshtml.IHTMLElement element)
        {
            if (element == null)
            {
                return("");
            }
            mshtml.IHTMLElement currentNode = element;
            ArrayList           path        = new ArrayList();

            while (currentNode != null)
            {
                string pe = getNode(currentNode);
                if (pe != null)
                {
                    path.Add(pe);
                    if (pe.IndexOf("@id") != -1)
                    {
                        break;  // Found an ID, no need to go upper, absolute path is OK
                    }
                }
                currentNode = currentNode.parentElement;
            }
            path.Reverse();
            return(join(path, "/"));
        }
Exemple #13
0
        /// <summary>
        /// 获取CSS Selector(当包含上下文的时候调用此方法)
        /// http://stackoverflow.com/questions/3390396/how-to-check-for-undefined-in-javascript
        /// </summary>
        /// <param name="element"></param>
        public string GetContextSelector(mshtml.IHTMLElement context, mshtml.IHTMLElement element)
        {
            SetContextSelector(context);
            var originalId = element.id;

            if (string.IsNullOrEmpty(originalId))
            {
                var id = "__" + IEUtils.IEVariableNameHelper.CreateVariableName();
                element.id = id;
            }
            mshtml.IHTMLWindow2 parentWindow = ((IHTMLDocument2)(element.document)).parentWindow as mshtml.IHTMLWindow2;
            IEUtils.RunScript(ScriptLoader.GetJquerySelector(""), parentWindow);
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("var el = $jq('#{0}');", element.id));
            sb.AppendLine();

            sb.Append("if(typeof __context == 'undefined'){");
            sb.AppendLine();
            sb.Append("__context = '';");
            sb.AppendLine();
            sb.Append("}");
            sb.AppendLine();
            sb.Append(" var selector = el.getCssPath(__context);");
            sb.AppendLine();
            sb.Append("__context = 'undefined';");
            sb.Append("return selector");
            object result = JS.FunEval(AppContext.Current.Window, sb.ToString());

            element.id = originalId;
            return(result == null ? "" : result.ToString());
        }
Exemple #14
0
        /// <summary>
        /// 获取CSS Selector(当包含上下文的时候调用此方法)
        /// http://stackoverflow.com/questions/3390396/how-to-check-for-undefined-in-javascript
        /// </summary>
        /// <param name="element"></param>
        public void SetSelector(mshtml.IHTMLElement element)
        {
            var originalId = element.id;

            if (string.IsNullOrEmpty(originalId))
            {
                var id = "__" + IEUtils.IEVariableNameHelper.CreateVariableName();
                element.id = id;
            }
            mshtml.IHTMLWindow2 parentWindow = ((IHTMLDocument2)(element.document)).parentWindow as mshtml.IHTMLWindow2;
            IEUtils.RunScript(ScriptLoader.GetJquerySelector(""), parentWindow);
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("var el = $jq('#{0}');", element.id));
            sb.AppendLine();

            sb.Append("if(typeof __context == 'undefined'){");
            sb.AppendLine();
            sb.Append("__context = '';");
            sb.AppendLine();
            sb.Append("}");
            sb.AppendLine();
            sb.Append(" var selector = el.getCssPath(__context);");
            sb.AppendLine();

            sb.Append("el.attr('__selector', selector);");
            //sb.Append("alert(el.attr('__selector'));");
            //sb.AppendLine();

            IEUtils.RunScript(sb.ToString(), parentWindow);
            element.id = originalId;
        }
Exemple #15
0
        private string getNode(mshtml.IHTMLElement node, bool fullPath)
        {
            string nodeExpr = node.tagName;

            if (nodeExpr == null)  // Eg. node = #text
            {
                return(null);
            }
            if (node.id != "" && node.id != null && !fullPath)
            {
                nodeExpr += "#" + node.id;
                // We don't really need to go back up to //HTML, since IDs are supposed
                // to be unique, so they are a good starting point.
                return(nodeExpr);
            }

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

            mshtml.IHTMLDOMNode nodeDom = node as mshtml.IHTMLDOMNode;
            mshtml.IHTMLDOMNode psDom   = nodeDom.previousSibling;
            psDom = SkipText(psDom);
            mshtml.IHTMLElement ps = psDom as mshtml.IHTMLElement;
            while (ps != null)
            {
                if (ps.tagName == node.tagName)
                {
                    rank++;
                }
                psDom = psDom.previousSibling;
                psDom = SkipText(psDom);
                ps    = psDom as mshtml.IHTMLElement;
            }
            if (rank > 0)
            {
                nodeExpr += ":eq(" + rank + ")";
            }
            else
            { // First node of its kind at this level. Are there any others?
                mshtml.IHTMLDOMNode nsDom = nodeDom.nextSibling;
                while (nsDom != null && nsDom.nodeName == "#text")
                {
                    nsDom = nsDom.nextSibling;
                }
                //nsDom = SkipText(nsDom);
                mshtml.IHTMLElement ns = nsDom as mshtml.IHTMLElement;
                while (ns != null)
                {
                    if (ns.tagName == node.tagName)
                    { // Yes, mark it as being the first one
                        nodeExpr += ":eq(0)";
                        break;
                    }
                    nsDom = nsDom.nextSibling;
                    ns    = nsDom as mshtml.IHTMLElement;
                }
            }
            return(nodeExpr);
        }
Exemple #16
0
 public void RestoreOriginalAttribute()
 {
     mshtml.IHTMLElement el = element as mshtml.IHTMLElement;
     el.style.setAttribute("outline-style", originalOutlineStyle, 1);
     el.style.setAttribute("outline-color", originalOutlineColor, 1);
     el.style.setAttribute("outline-width", originalOutlineWidth, 1);
     el.style.setAttribute("background-color", originalBackgroundColor, 1);
 }
Exemple #17
0
        private FindAttribute GetXPathFinder(IHTMLElement element)
        {
            FindAttribute Finder = Finder = new FindAttribute();

            Finder.FindMethod = FindMethods.XPath;
            Finder.FindValue  = XPathFinder.GetXPath(element);
            return(Finder);
        }
Exemple #18
0
 //invoke the UpdateUI event
 public void InvokeUpdateUI(mshtml.IHTMLElement ae)
 {
     if (UpdateUI != null)
     {
         HtmlUpdateUIEventArgs ea = new HtmlUpdateUIEventArgs();
         ea.currentElement = ae;
         UpdateUI(this, ea);
     }
 }
Exemple #19
0
        public override bool Parse(ActionBuilder.ActionParameter parameter)
        {
            ActionClickParameter ap            = parameter as ActionClickParameter;
            IHTMLElement         activeElement = ap.Element;

            if (activeElement == null)
            {
                return(false);
            }
            base.Parse(parameter);
            bool result = false;

            switch (ElementType)
            {
            case ElementTypes.SelectList:
                //注入onchange事件
                RunScript(ScriptLoader.GetSelectChangeEventTrigger(), true);
                result = true;
                break;

            case ElementTypes.Button:
            case ElementTypes.Image:
            case ElementTypes.Link:
            case ElementTypes.TextField:
            case ElementTypes.CheckBox:
            case ElementTypes.RadioButton:
                result = true;
                break;

            case ElementTypes.Area:
            case ElementTypes.Body:
            case ElementTypes.Form:
            case ElementTypes.Frame:
            case ElementTypes.Label:
            case ElementTypes.Para:
            case ElementTypes.Table:
            case ElementTypes.TableBody:
            case ElementTypes.TableCell:
            case ElementTypes.TableRow:
            case ElementTypes.Element:
            case ElementTypes.Div:
            case ElementTypes.Span:
                if (ap.Filter == ActionFliter.Lower)
                {
                    result = true;
                }
                break;

            default:
                break;
            }

            return(result);
        }
        private static string getNode(mshtml.IHTMLElement node)
        {
            string nodeExpr = node.tagName;

            if (nodeExpr == null)  // Eg. node = #text
            {
                return(null);
            }
            if (node.id != "" && node.id != null)
            {
                nodeExpr += "[@id='" + node.id + "']";
                // We don't really need to go back up to //HTML, since IDs are supposed
                // to be unique, so they are a good starting point.
                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);
        }
Exemple #21
0
        public static bool GetRadioRect(mshtml.IHTMLDocument2 doc, ref Rectangle rect, string itemName, string tagStr, string indexStr)
        {
            bool flag = false;

            mshtml.IHTMLElement elem = GetRadioElement(doc, itemName, tagStr, indexStr);
            if (elem != null)
            {
                rect = GetElementRect(doc.body, elem);
                flag = true;
            }
            return(flag);
        }
Exemple #22
0
        //로그인 과정
        private void login()
        {
            if (doc.GetElementById("login-input") != null)
            {
                nStep = "trylogin";

                doc.GetElementById("id-pw").GetElementsByTagName("input").GetElementsByName("user_id")[0].SetAttribute("value", user_id);
                doc.GetElementById("id-pw").GetElementsByTagName("input").GetElementsByName("password")[0].SetAttribute("value", user_pw);

                mshtml.IHTMLElement hel = doc.GetElementById("login-process").GetElementsByTagName("input")[0].DomElement as mshtml.IHTMLElement;
                hel.click();
            }
        }
Exemple #23
0
 public void ChangeElementAttribute()
 {
     mshtml.IHTMLElement el          = element as mshtml.IHTMLElement;
     string[]            excludeTags = new string[] { "head", "meta", "style", "script", "noscript", "link" };
     if (excludeTags.Contains(el.tagName.ToLower()))
     {
         return;
     }
     el.style.setAttribute("outline-style", OutlineStyle, 1);
     el.style.setAttribute("outline-color", OutlineColor, 1);
     el.style.setAttribute("outline-width", OutlineWidth, 1);
     el.style.setAttribute("background-color", BackgroundColor, 1);
 }
Exemple #24
0
        public void SetFindMethod(IHTMLElement element, FindMethods method, string value)
        {
            FindAttribute Finder = new FindAttribute();

            Finder.FindMethod = method;
            Finder.FindValue  = value;
            FindMechanism.Add(Finder);
            if (element == null)
            {
                return;
            }
            SetFrameList(element);
            ElementType = TagStringToElementType(element);
        }
Exemple #25
0
        //空间动态里的好友
        private void button9_Click(object sender, EventArgs e)
        {
            string info = "";

            mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass;

            for (int i = 0; i < htmlDoc.frames.length; ++i)
            {
                object index = i;
                mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2;

                IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow);

                for (int j = 0; j < frame.frames.length; ++j)
                {
                    try
                    {
                        object rj = j;
                        mshtml.IHTMLWindow2 frameWindow2 = frame.frames.item(ref rj) as mshtml.IHTMLWindow2;

                        IHTMLDocument2 frame2 = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow2);
                        mshtml.IHTMLElementCollection userlist = (mshtml.IHTMLElementCollection)frame2.all.tags("div");
                        IEnumerator users = userlist.GetEnumerator();
                        while (users.MoveNext())
                        {
                            mshtml.IHTMLElement element = (mshtml.IHTMLElement)users.Current;
                            if (element.className == "user-list" || element.className == "ui-avatar")
                            {
                                mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.children;
                                IEnumerator cusers = childrenCol.GetEnumerator();
                                while (cusers.MoveNext())
                                {
                                    mshtml.IHTMLElement celement = (mshtml.IHTMLElement)cusers.Current;
                                    string href = (string)celement.getAttribute("href", 0);
                                    if (href.Contains("http:"))
                                    {
                                        info += href + "\n";
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            MessageBox.Show(info);
        }
Exemple #26
0
        //3.提交
        private bool commentStep3ex(mshtml.IHTMLElement commentTag)
        {
            if (commentTag == null)
            {
                return(false);
            }
            mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass;
            for (int i = 0; i < htmlDoc.frames.length; ++i)
            {
                object index = i;
                mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2;

                IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow);

                mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("div");
                IEnumerator tagie = tagls.GetEnumerator();
                while (tagie.MoveNext())
                {
                    mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current;
                    if (commentTag == element && element.className == "mod-comments")
                    {
                        mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.all;
                        IEnumerator cusers = childrenCol.GetEnumerator();
                        while (cusers.MoveNext())
                        {
                            mshtml.IHTMLElement element2 = (mshtml.IHTMLElement)cusers.Current;
                            if (element2.className == "btn-post gb_bt  evt_click")
                            {
                                element2.click();
                                return(true);

//                                 mshtml.IHTMLElementCollection element2Col = (mshtml.IHTMLElementCollection)element2.all;
//                                 IEnumerator element2Cols = element2Col.GetEnumerator();
//                                 while (element2Cols.MoveNext())
//                                 {
//                                     mshtml.IHTMLElement element3 = (mshtml.IHTMLElement)element2Cols.Current;
//                                     if (element3.className == "btn-post gb_bt  evt_click")
//                                     {
//                                         element3.click();
//                                         return commentTag;
//                                     }
//                                 }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Exemple #27
0
        public static bool GetButtonRect(mshtml.IHTMLDocument2 doc, ref Rectangle rect, string itemName, string tagStr, string indexStr)
        {
            mshtml.IHTMLElement elem = GetButtonElement(doc, itemName, tagStr, indexStr);
            bool flag = false;

            if (elem != null)
            {
                rect = GetElementRect(doc.body, elem);
                flag = true;
            }
            if (elem != null)
            {
                Marshal.ReleaseComObject(elem);
            }
            return(flag);
        }
Exemple #28
0
        public void SaveOriginalAttribute()
        {
            mshtml.IHTMLElement el = element as mshtml.IHTMLElement;
            Object att             = el.style.getAttribute("outline-style", 0);

            originalOutlineStyle = (att != null ? att.ToString() : "");

            att = el.style.getAttribute("outline-color", 0);
            originalOutlineColor = (att != null ? att.ToString() : "");

            att = el.style.getAttribute("outline-width", 0);
            originalOutlineWidth = (att != null ? att.ToString() : "");

            att = el.style.getAttribute("background-color", 0);
            originalBackgroundColor = (att != null ? att.ToString() : "");
        }
Exemple #29
0
        public static mshtml.IHTMLElement GetButtonElement(mshtml.IHTMLDocument2 doc, string itemName, string tagStr, string indexStr)
        {
            mshtml.IHTMLElement element = null;
            ElementTag          iD      = ElementTag.ID;
            int num  = 0;
            int num2 = 0;

            if ((indexStr != string.Empty) && (indexStr != ""))
            {
                num2 = WindowUtil.StringToInt(indexStr);
            }
            if ((tagStr != string.Empty) && (tagStr != ""))
            {
                iD = (ElementTag)WindowUtil.StringToInt(tagStr);
            }
            mshtml.IHTMLElementCollection o = (mshtml.IHTMLElementCollection)doc.all.tags("input");
            foreach (mshtml.IHTMLElement element2 in o)
            {
                if ((IsElementMatchType(element2, "submit") || IsElementMatchType(element2, "button")) && IsElementMatch(element2, iD, itemName, ""))
                {
                    if (num == num2)
                    {
                        element = element2;
                        break;
                    }
                    num++;
                }
            }
            if (o != null)
            {
                Marshal.ReleaseComObject(o);
            }
            o = (mshtml.IHTMLElementCollection)doc.all.tags("button");
            foreach (mshtml.IHTMLElement element3 in o)
            {
                if (IsElementMatch(element3, iD, itemName, ""))
                {
                    if (num == num2)
                    {
                        return(element3);
                    }
                    num++;
                }
            }
            return(element);
        }
        private void load(bool cancel, NavigatingCancelEventArgs e)
        {
            mshtml.HTMLDocument c = (mshtml.HTMLDocument)webBrowser1.Document;
            if (c != null)
            {
                if (currentEl != null)
                    currentEl.style.backgroundColor = "#ffffff";

                richTextBox1.Document.Blocks.Clear();
                if(e != null)
                    e.Cancel = cancel;
                string html = c.activeElement.outerHTML;
                currentEl = c.activeElement;
                c.activeElement.style.backgroundColor = "#F0FF06";
                richTextBox1.AppendText(html);
            }
        }
Exemple #31
0
        private FindAttribute GetCssPathFinder(IHTMLElement element)
        {
            FindAttribute Finder = Finder = new FindAttribute();

            Finder.FindMethod = FindMethods.CssSelector;
            string selector = element.getAttribute("__selector", 0) as string;

            if (!string.IsNullOrEmpty(selector))
            {
                Finder.FindValue = selector;
            }
            else
            {
                Finder.FindValue = this.AppContext.Browser.Selector.GetCssPath(element, false);
            }
            return(Finder);
        }
        /// <summary>
        /// Show custom Context Menu for Image.
        /// </summary>
        /// <param name="dwID">
        /// A DWORD that specifies the identifier of the shortcut menu to be displayed. 
        /// See NativeMethods.CONTEXT_MENU_CONST.
        /// </param>
        /// <param name="pt">
        /// The screen coordinates for the menu.
        /// </param>
        /// <param name="pcmdtReserved"></param>
        /// <param name="pdispReserved">
        /// The object at the screen coordinates specified in ppt. This enables a host to
        /// pass particular objects, such as anchor tags and images, to provide more 
        /// specific context.
        /// </param>
        /// <returns>
        /// Return 0 means that host displayed its UI. MSHTML will not attempt to display its UI. 
        /// </returns>
        public int ShowContextMenu(int dwID, POINT pt, object pcmdtReserved, object pdispReserved)
        {
            try
            {
                this.clickedElement = pdispReserved as mshtml.IHTMLElement;

                if (this.adding)
                {
                    this.menuItemUsername.Visible = true;
                    this.menuItemPassword.Visible = true;
                    this.menuItemEnter.Visible = true;

                    string type = "";
                    try
                    {
                        type = this.clickedElement.getAttribute("type").ToString();
                    }
                    catch (Exception ee) {}

                    if (type.ToUpper() == "TEXT")
                    {
                        this.menuItemPassword.Visible = false;
                        this.menuItemEnter.Visible = false;
                    }
                    else if (type.ToUpper() == "PASSWORD")
                    {
                        this.menuItemUsername.Visible = false;
                        this.menuItemEnter.Visible = false;
                    }
                    else
                    {
                        this.menuItemUsername.Visible = false;
                        this.menuItemPassword.Visible = false;
                        this.menuItemEnter.Visible = true;
                        this.menuItemCancel.Visible = true;
                    }

                    contextMenu.Show(pt.x, pt.y);

                    return 0;
                }
                else if (!this.adding)
                {
                    contextMenu.Show(pt.x + 2, pt.y - 47);

                    this.menuItemUsername.Visible = false;
                    this.menuItemPassword.Visible = false;
                    this.menuItemEnter.Visible = false;
                    this.menuItemCancel.Visible = false;

                    return 1;

                }
                else
                {
                    return 1;
                }
            }
            catch (Exception e)
            {
                Utils.l(e);
                return 1;
            }
        }
        void AddAutoHandler(object sender, EventArgs e)
        {
            DialogResult dr = System.Windows.Forms.MessageBox.Show("Para poder agregar el nuevo sitio a 1000Pass.com es necesario que haya ingresado su usuario y clave. Ya lo ha hecho?", "1000pass.com", MessageBoxButtons.YesNo);

            if (dr == System.Windows.Forms.DialogResult.Yes)
            {

                IHTMLDocument3 htmlDoc = (IHTMLDocument3)ieInstance.Document;
                IHTMLElementCollection possibleElements = htmlDoc.getElementsByTagName("INPUT");
                IHTMLElement passwordElement = null;
                IHTMLElement usernameElement = null;
                IHTMLElement enterElement = null;
                int c = 0;
                foreach (IHTMLElement possibleElement in possibleElements)
                {
                    // Only not empty input type password
                    if (possibleElement.getAttribute("type").ToString().ToUpper() == "PASSWORD"
                        && !String.IsNullOrEmpty(((IHTMLInputElement)possibleElement).value))
                    {
                        c++;
                        passwordElement = possibleElement;
                    }
                }

                if (c == 1)
                {
                    int cc = 0;
                    IHTMLFormElement form = ((IHTMLInputElement)passwordElement).form;
                    if (form != null)
                    {
                        foreach (IHTMLElement possibleElement in possibleElements)
                        {
                            string type = possibleElement.getAttribute("type").ToString().ToUpper();
                            if (type == "TEXT" || type == "SUBMIT")
                            {
                                IHTMLFormElement possibleForm = ((IHTMLInputElement)possibleElement).form;
                                if (possibleForm.Equals(form))
                                {
                                    if (type == "TEXT")
                                    {
                                        usernameElement = possibleElement;
                                        cc++;
                                    }
                                    else if (type == "SUBMIT")
                                    {
                                        enterElement = possibleElement;
                                        cc++;
                                    }
                                }
                            }
                        }

                        // Enter element may be a button type submit too!
                        if (cc == 1 && enterElement == null)
                        {
                            possibleElements = htmlDoc.getElementsByTagName("BUTTON");
                            foreach (IHTMLElement possibleElement in possibleElements)
                            {
                                string type = possibleElement.getAttribute("type").ToString().ToUpper();
                                if (type == "SUBMIT")
                                {
                                    if (((IHTMLButtonElement)possibleElement).form.Equals(form))
                                    {
                                        enterElement = possibleElement;
                                        cc++;
                                    }
                                }
                            }
                        }

                        if (cc == 2
                            && passwordElement != null
                            && usernameElement != null
                            && enterElement != null)
                        {

                            this.usernameValue = ((IHTMLInputElement)usernameElement).value;
                            if (String.IsNullOrEmpty(this.usernameValue))
                            {
                                Utils.l(EMPTY_USERNAME);
                                return;
                            }
                            else
                            {
                                this.clickedElement = usernameElement;
                                this.username = Utils.FindXPath(usernameElement);
                                MarkAsSelected(USERNAME);
                            }

                            this.passwordValue = ((IHTMLInputElement)passwordElement).value;
                            if (String.IsNullOrEmpty(this.passwordValue))
                            {
                                Utils.l(EMPTY_PASSWORD);
                                return;
                            }
                            else
                            {
                                this.clickedElement = passwordElement;
                                this.password = Utils.FindXPath(passwordElement);
                                MarkAsSelected(PASSWORD);
                            }

                            this.clickedElement = enterElement;
                            this.enter = Utils.FindXPath(enterElement);
                            MarkAsSelected(ENTER);

                            Send();
                        }
                        else
                        {
                            this.adding = true;

                            this.menuItemAddManual.Visible = false;
                            this.menuItemAddAuto.Visible = false;

                            this.menuItemUsername.Visible = false;
                            this.menuItemPassword.Visible = false;
                            this.menuItemEnter.Visible = false;

                            if (usernameElement == null)
                            {
                                this.menuItemUsername.Enabled = true;
                                this.menuItemUsername.Visible = true;
                            }
                            else
                            {
                                this.clickedElement = usernameElement;
                                this.username = Utils.FindXPath(usernameElement);
                                this.usernameValue = ((IHTMLInputElement)usernameElement).value;
                                MarkAsSelected(USERNAME);
                            }

                            if (passwordElement == null)
                            {
                                this.menuItemPassword.Enabled = true;
                                this.menuItemPassword.Visible = true;
                            }
                            else
                            {
                                this.clickedElement = passwordElement;
                                this.password = Utils.FindXPath(passwordElement);
                                this.passwordValue = ((IHTMLInputElement)passwordElement).value;
                                MarkAsSelected(PASSWORD);
                            }

                            if (enterElement == null)
                            {
                                this.menuItemEnter.Enabled = true;
                                this.menuItemEnter.Visible = true;
                            }
                            else
                            {
                                this.clickedElement = enterElement;
                                this.enter = Utils.FindXPath(enterElement);
                                MarkAsSelected(ENTER);
                            }

                            Utils.l(@"No podemos encontrar todos los campo en forma automatica. Por favor, agregue los campos restantes en manualmente presionando el boton derecho sobre los elementos que no se pudieron encontrar.");
                        }
                    } // form == null
                }
                else
                {
                    Utils.l(@"Existe mas de un campo de tipo clave en esta pagina. Por favor, agregue los campos en forma manual.");
                }
            }
        }
        bool iEvent_onclick(mshtml.IHTMLEventObj pEvtObj)
        {
            if (currentEl != null)
                currentEl.style.backgroundColor = "#ffffff";

            mshtml.HTMLDocument doc = (mshtml.HTMLDocument)webBrowser1.Document;
            mshtml.IHTMLWindow2 win = doc.parentWindow;
            richTextBox1.Document.Blocks.Clear();
            currentEl = [email protected];
            richTextBox1.AppendText([email protected]);

            foreach (IHTMLElement el in [email protected])
            {
                if(el.tagName == [email protected])
                    el.style.backgroundColor = "#F0FF06";

                foreach (IHTMLElement e in el.all)
                {
                    if (e.tagName == [email protected])
                        el.style.backgroundColor = "#F0FF06";
                }
            }

            [email protected] = "#F0FF06";
            return false;
        }