Ejemplo n.º 1
0
        GeckoElement FindTagContainingText(GeckoDocument doc, string text)
        {
            string[] tagtypes =
            {
                "h1",
                "h2",
                "h3",
                "h4",
                "h5",
                "h6",
                "a",
                "div",
                "p",
                "span",
            };

            foreach (string tagtype in tagtypes)
            {
                foreach (GeckoElement elem in doc.GetElementsByTagName(tagtype))
                {
                    if (elem.InnerHtml.Trim() == text.Trim())
                    {
                        return(elem);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void AddScriptContent(string content)
        {
            GeckoDocument      doc    = WebBrowser.Document;
            var                head   = doc.GetElementsByTagName("head").First();
            GeckoScriptElement script = doc.CreateElement("script") as GeckoScriptElement;

            script.Type = "text/javascript";
            script.Text = content;
            head.AppendChild(script);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// add a jscript source file
        /// </summary>
        /// <param name="filename"></param>
        public void AddScriptSource(string filename)
        {
            if (!File.Exists(Path.Combine(Path.GetDirectoryName(_url), filename)))
            {
                throw new FileNotFoundException(filename);
            }

            GeckoDocument      doc    = WebBrowser.Document;
            var                head   = doc.GetElementsByTagName("head").First();
            GeckoScriptElement script = doc.CreateElement("script") as GeckoScriptElement;

            script.Type = "text/javascript";
            script.Src  = filename;
            head.AppendChild(script);
        }
Ejemplo n.º 4
0
        private void _okButton_Click(object sender, EventArgs e)
        {
            GeckoDocument doc = _browser.WebBrowser.Document;

            var body             = doc.GetElementsByTagName("body").First();
            GeckoHtmlElement div = doc.CreateElement("div") as GeckoHtmlElement;

            div.Id = "output";
            body.AppendChild(div);

            _browser.RunJavaScript("gatherSettings()");

            FormData     = div.InnerHtml;
            DialogResult = DialogResult.OK;
            Close();
        }
        public void AddVoiceActions(GeckoDocument document, string tagName)
        {
            foreach (GeckoElement element in document.GetElementsByTagName(tagName))
            {
                VoiceAction action = new VoiceAction();
                action.label = element.TextContent.Trim();

                if (tagName == "button")
                {
                    action.task += () =>
                    {
                        GeckoButtonElement button = new GeckoButtonElement(element.DomObject);
                        button.Click();
                    };
                }

                if (tagName == "a")
                {
                    action.task += () =>
                    {
                        GeckoAnchorElement anchor = new GeckoAnchorElement(element.DomObject);
                        anchor.Click();
                    };
                }

                if (tagName == "iframe")
                {
                    action.task += () =>
                    {
                        GeckoButtonElement iframe = new GeckoButtonElement(element.DomObject);
                        iframe.Click();
                    };
                }
                actions.Add(action);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 private GeckoHtmlElement getGeckoHtmlElementSubmit(GeckoDocument document)
 {
     GeckoElementCollection nodes = document.GetElementsByTagName("input");
     if (nodes == null) return null;
     foreach (GeckoElement node in nodes)
     {
         String type = ((GeckoHtmlElement)node).GetAttribute("type");
         if (type != null && type.ToUpper() == "SUBMIT")
         {
             String value = ((GeckoHtmlElement)node).GetAttribute("value");
             if (value != null && (value.ToUpper() == "CONTINUE" || value.ToUpper() == "SUBMIT" || value.ToUpper() == "CONFIRM" || value.ToUpper() == "CHẤP NHẬN" || value.ToUpper() == "GỬI" || value.ToUpper() == "TIẾP TỤC"))
             {
                 return (GeckoHtmlElement)node;
             }
         }
     }
     return null;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 private GeckoHtmlElement getGeckoHtmlElementLogout(GeckoDocument document)
 {
     GeckoElementCollection nodes = document.GetElementsByTagName("a");
     if (nodes == null) return null;
     foreach (GeckoElement node in nodes)
     {
         String href = ((GeckoHtmlElement)node).GetAttribute("href");
         if (href != null && href.Contains("logout.php"))
         {
             String logoutHtml = ((GeckoHtmlElement)node).InnerHtml;
             if (logoutHtml.StartsWith("Logout") || logoutHtml.StartsWith("Đăng xuất") || logoutHtml.StartsWith("Log out") || logoutHtml.StartsWith("Log Out"))
             {
                 return (GeckoHtmlElement)node;
             }
             else
             {
                 return null;
             }
         }
     }
     return null;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 private GeckoHtmlElement getGeckoHtmlElementNextWizard(GeckoDocument document)
 {
     //NEXT
     GeckoElementCollection nodes = document.GetElementsByTagName("a");
     if (nodes == null) return null;
     foreach (GeckoElement node in nodes)
     {
         if (node.TextContent == "Tiếp" || node.TextContent == "Next")
         {
             return ((GeckoHtmlElement)node);
         }
     }
     //SAVE SETTINGS
     nodes = document.GetElementsByTagName("input");
     foreach (GeckoElement node in nodes)
     {
         String type = ((GeckoHtmlElement)node).GetAttribute("type");
         if (type != null && type.ToUpper() == "SUBMIT")
         {
             String value = ((GeckoHtmlElement)node).GetAttribute("value");
             if (value != null && (value.ToUpper() == "LƯU CÀI ĐẶT" || value.ToUpper() == "SAVE SETTINGS"))
             {
                 return ((GeckoHtmlElement)node);
             }
             String name = ((GeckoHtmlElement)node).GetAttribute("name");
             if (name != null && (name == "submit[Continue]"))
             {
                 return ((GeckoHtmlElement)node);
             }
         }
     }
     return null;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 private GeckoHtmlElement getGeckoHtmlElementInput(GeckoDocument document)
 {
     GeckoElementCollection nodes = document.GetElementsByTagName("input");
     if (nodes == null) return null;
     foreach (GeckoElement node in nodes)
     {
         String type = node.GetAttribute("type");
         if (type != "hidden") return (GeckoHtmlElement) node;
     }
     return null;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 private GeckoHtmlElement getGeckoHtmlElementInvalid(GeckoDocument document)
 {
     GeckoElementCollection nodes = document.GetElementsByTagName("span");
     if (nodes == null) return null;
     foreach (GeckoElement node in nodes)
     {
         String html = ((GeckoHtmlElement)node).InnerHtml;
         if (html != null && (html.Contains("bạn đã có tài khoản") || html.Contains("Không thể xác thực") || html.Contains("lòng thử lại số khác") || html.Contains("try a different number") || html.Contains("sử dụng một địa chỉ email hoặc số di động") || html.Contains("already in use by a registered account") || html.Contains("Could not validate your mobile number")))
         {
             return (GeckoHtmlElement)node;
         }
     }
     return null;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 private GeckoHtmlElement getGeckoHtmlElementHelp(GeckoDocument document)
 {
     GeckoElementCollection nodes = document.GetElementsByTagName("a");
     if (nodes == null) return null;
     foreach (GeckoElement node in nodes)
     {
         String href = ((GeckoHtmlElement)node).GetAttribute("href");
         if (href != null && (href.Contains("/help/212848065405122") || href.Contains("/help/174987089221178")))
         {
             return (GeckoHtmlElement)node;
         }
     }
     return null;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 private GeckoHtmlElement getGeckoHtmlElementCode(GeckoDocument document)
 {
     GeckoElementCollection nodes = document.GetElementsByTagName("input");
     if (nodes == null) return null;
     foreach (GeckoElement node in nodes)
     {
         String name = ((GeckoHtmlElement)node).GetAttribute("name");
         if (name != null && name.Contains("code")) return (GeckoHtmlElement)node;
         String style = ((GeckoHtmlElement)node).GetAttribute("style");
         if (style != null && style.Contains("-wap-input-format")) return (GeckoHtmlElement)node;
     }
     return null;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 private GeckoHtmlElement getGeckoHtmlElementAcceptPlay(GeckoDocument document)
 {
     //logout.php
     GeckoElementCollection nodes = document.GetElementsByTagName("button");
     if (nodes == null) return null;
     foreach (GeckoElement node in nodes)
     {
         String name = ((GeckoHtmlElement)node).GetAttribute("name");
         if (name == "__CONFIRM__")
         {
             return ((GeckoHtmlElement)node);
         }
     }
     return null;
 }
Ejemplo n.º 14
0
        GeckoElement FindTagContainingText(GeckoDocument doc, string text)
        {
            string[] tagtypes = {
                                    "h1",
                                    "h2",
                                    "h3",
                                    "h4",
                                    "h5",
                                    "h6",
                                    "a",
                                    "div",
                                    "p",
                                    "span",
                                };

            foreach (string tagtype in tagtypes)
            {
                foreach (GeckoElement elem in doc.GetElementsByTagName(tagtype))
                {
                    if (elem.InnerHtml.Trim() == text.Trim())
                    {
                        return elem;
                    }
                }
            }

            return null;
        }
Ejemplo n.º 15
0
        private GeckoHtmlElement GetElementByXpath(GeckoDocument doc, string xpath)
        {
            if (doc == null) return null;

            xpath = xpath.Replace("/html/", "");
            GeckoElementCollection eleColec = doc.GetElementsByTagName("html"); if (eleColec.Length == 0) return null;
            GeckoHtmlElement ele = eleColec[0];
            string[] tagList = xpath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string tag in tagList)
            {
                System.Text.RegularExpressions.Match mat = System.Text.RegularExpressions.Regex.Match(tag, "(?<tag>.+)\\[@id='(?<id>.+)'\\]");
                if (mat.Success == true)
                {
                    string id = mat.Groups["id"].Value;
                    GeckoHtmlElement tmpEle = doc.GetHtmlElementById(id);
                    if (tmpEle != null) ele = tmpEle;
                    else
                    {
                        ele = null;
                        break;
                    }
                }
                else
                {
                    mat = System.Text.RegularExpressions.Regex.Match(tag, "(?<tag>.+)\\[(?<ind>[0-9]+)\\]");
                    if (mat.Success == false)
                    {
                        GeckoHtmlElement tmpEle = null;
                        foreach (GeckoNode it in ele.ChildNodes)
                        {
                            if (it.NodeName.ToLower() == tag)
                            {
                                tmpEle = (GeckoHtmlElement)it;
                                break;
                            }
                        }
                        if (tmpEle != null) ele = tmpEle;
                        else
                        {
                            ele = null;
                            break;
                        }
                    }
                    else
                    {
                        string tagName = mat.Groups["tag"].Value;
                        int ind = int.Parse(mat.Groups["ind"].Value);
                        int count = 0;
                        GeckoHtmlElement tmpEle = null;
                        foreach (GeckoNode it in ele.ChildNodes)
                        {
                            if (it.NodeName.ToLower() == tagName)
                            {
                                count++;
                                if (ind == count)
                                {
                                    tmpEle = (GeckoHtmlElement)it;
                                    break;
                                }
                            }
                        }
                        if (tmpEle != null) ele = tmpEle;
                        else
                        {
                            ele = null;
                            break;
                        }
                    }
                }
            }

            return ele;
        }