private void AttachContextMenu(HtmlElement he)
        {
            if (he.TagName.Equals(TagNames.BodyTagName))
            {
                if (bodyContextMenu == null)
                {
                    InitializeBodyContextMenu();
                }
            }

            if (he.TagName.Equals(TagNames.AnchorTagName))
            {
                if (!he.GetAttribute("href").Equals(string.Empty))
                {
                    if (linkContextMenu == null)
                    {
                        InitializeLinkContextMenu();
                    }
                }
            }

            if (he.TagName.Equals(TagNames.ImageTagName))
            {
                if (!he.GetAttribute("longdesc").Equals(string.Empty))
                {
                    InitializeEquationContextMenu();
                }
            }
        }
Exemple #2
0
		public static string SafeAttribute(HtmlElement htmlNode, string strName)
		{
			if(htmlNode == null) { Debug.Assert(false); return string.Empty; }
			if(string.IsNullOrEmpty(strName)) { Debug.Assert(false); return string.Empty; }

			string strValue = (htmlNode.GetAttribute(strName) ?? string.Empty);

			// http://msdn.microsoft.com/en-us/library/ie/ms536429.aspx
			if((strValue.Length == 0) && strName.Equals("class", StrUtil.CaseIgnoreCmp))
				strValue = (htmlNode.GetAttribute("className") ?? string.Empty);

			return strValue;
		}
Exemple #3
0
 public HtmlCheckBox(HtmlElement element)
     : base(element.Id)
 {
     // 如果checkbox的有属性是“checked”它将被检查。
     string chekced = element.GetAttribute("checked");
     Checked = !string.IsNullOrEmpty(chekced);
 }
        public static HtmlInputElement GetInputElement(HtmlElement element)
        {
            if (!element.TagName.Equals("input", StringComparison.OrdinalIgnoreCase))
            {
                return null;
            }

            HtmlInputElement input = null;

            string type = element.GetAttribute("type").ToLower();

            switch (type)
            {
                case "checkbox":
                    input = new HtmlCheckBox(element);
                    break;
                case "password":
                    input = new HtmlPassword(element);
                    break;
                case "submit":
                    input = new HtmlSubmit(element);
                    break;
                case "text":
                    input = new HtmlText(element);
                    break;
                default:
                    break;

            }
            return input;
        }
Exemple #5
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="pElement"></param>
 public ParaRefer(HtmlElement pElement)
 {
     if ("option".Equals(pElement.TagName, StringComparison.OrdinalIgnoreCase))
     {
         Name = pElement.InnerText;
         Value = pElement.GetAttribute("value");
     }
     else
     {
         Name = pElement.GetAttribute("value");
         Value = Name;
     }
     if (Value != null)
     {
         Value = Name.Replace(" ", "+");
     }
 }
Exemple #6
0
		/// <summary>
		/// 根据 HtmlElement 创建标记对象.
		/// </summary>
		/// <param name="element">用于创建标记对象的 HtmlElement.</param>
		/// <returns>ElementMark 对象.</returns>
		public static ElementMark Create ( HtmlElement element )
		{

			if ( null == element )
				throw new ArgumentNullException ( "element", "HtmlElement 不能为空" );

			return new ElementMark ( element.Id, element.TagName, element.Name, element.GetAttribute ( "class" ), element.GetAttribute ( "type" ), ( element.GetAttribute ( "type" ) == "text" || element.GetAttribute ( "type" ) == "password" ) ? string.Empty : element.GetAttribute ( "value" ), element.GetAttribute ( "href" ), IEBrowser.GetFramePath ( element ) );
		}
 /// <summary>
 /// kimarja az épület szintjét
 /// egyelőre sajnos a hint-ből
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 private int GetLevel(HtmlElement e)
 {
     string title = e.GetAttribute("title");
     string[] tt = title.Split(' ');
     int level;
     try
     {
         level = int.Parse(tt[tt.Length - 1]);
     }
     catch (Exception)
     {
         level = 0;
     }
     return level;
 }
        private void AttachHintDialogContextMenu(HtmlElement he)
        {
            if (he.TagName.Equals(TagNames.BodyTagName))
            {
                if (bodyContextMenu == null)
                {
                    InitializeHintDialogBodyContextMenu();
                }
            }

            if (he.TagName.Equals(TagNames.ImageTagName))
            {
                if (!he.GetAttribute("longdesc").Equals(string.Empty))
                {
                    InitializeHintDialogEquationContextMenu();
                }
            }
        }
 private HtmlElement SearchDiv(HtmlElement el)
 {
     if (el == null)
     {
         return null;
     }
     if (el.GetAttribute("className") == "WarningMessage PhaseOut")
     {
         return el;
     }
     HtmlElementCollection elc = el.GetElementsByTagName("div");
     if (elc != null)
     {
         foreach (HtmlElement e in elc)
         {
             HtmlElement r = SearchDiv(e);
             if (r != null)
             {
                 return r;
             }
         }
     }
     return null;
 }
Exemple #10
0
        private string GetCSSPath(HtmlElement element)
        {
            string CSSPath = string.Empty;
            string currentTagName;
            string className;

            while (element != null)
            {
                currentTagName = element.TagName;

                if (!string.IsNullOrEmpty(element.Id))
                {
                    CSSPath = element.TagName + "#" + element.Id + " " + CSSPath;
                }
                else if (!string.IsNullOrEmpty(className = element.GetAttribute("classname")))
                {
                    CSSPath = element.TagName + "." + className.Replace(" ", ".") + " " + CSSPath;
                }
                else
                {
                    CSSPath = element.TagName + " " + CSSPath;
                }

                element = element.Parent;
            }

            return CSSPath;
        }
Exemple #11
0
        private ElementPositionAndSelector getElementPositionAndSelector(HtmlElement elm)
        {
            Size size = elm.ClientRectangle.Size;
            if (size.Width == 0)
                size = elm.ScrollRectangle.Size;
            Point pos = elm.ClientRectangle.Location;

            string sFull = "";
            while (elm != null)
            {
                if (elm.TagName == "HTML")
                    break;

                string cls = elm.GetAttribute("classname");
                string id = elm.GetAttribute("id");

                if (!string.IsNullOrEmpty(id))
                    sFull = "#" + id + " > " + sFull;
                else if (!string.IsNullOrEmpty(cls))
                    sFull = elm.TagName + "." + cls + " > " + sFull;
                else if(elm.OffsetParent!=null)
                {
                    int index = elm.OffsetParent.GetElementsByTagName(elm.TagName).OfType<HtmlElement>().IndexOf(e => e == elm);
                    sFull = elm.TagName + "[" + index + "] > " + sFull;
                }

                pos.X += elm.OffsetRectangle.Left;
                pos.Y += elm.OffsetRectangle.Top;

                elm = elm.OffsetParent;
            }
            return new ElementPositionAndSelector {
                  Position = new Rectangle(pos, size),
                  Selector = sFull.Trim(' ','>')
              };
        }
 protected string TestHmtlEelementValue(HtmlElement he, string dbtable, string dbcolumn, int index)
 {
     string attribute = he.GetAttribute("value");
     if (string.IsNullOrEmpty(attribute))
     {
         return attribute;
     }
     DataSet dataSource = this.DataFormConntroller.DataSource;
     if (!dataSource.Tables.Contains(dbtable))
     {
         LoggingService.WarnFormatted("Table:{0},Column:{1} 关联的表没有找到...", new object[] { dbtable, dbcolumn });
         return attribute;
     }
     DataTable table = dataSource.Tables[dbtable];
     if (!table.Columns.Contains(dbcolumn))
     {
         LoggingService.WarnFormatted("Table:{0},Column:{1} 关联的表没有找到相应的列...", new object[] { dbtable, dbcolumn });
         return attribute;
     }
     DataRow row = dataSource.Tables[dbtable].Rows[index];
     DataColumn column = this.dataFormController.DataSource.Tables[dbtable].Columns[dbcolumn];
     System.Type dataType = column.DataType;
     if ((((!dataType.Equals(typeof(int)) && !dataType.Equals(typeof(long))) && (!dataType.Equals(typeof(double)) && !dataType.Equals(typeof(decimal)))) && !dataType.Equals(typeof(float))) && !dataType.Equals(typeof(float)))
     {
         return attribute;
     }
     int decimals = 2;
     if (dataType.Equals(typeof(int)) || dataType.Equals(typeof(long)))
     {
         decimals = 0;
     }
     else
     {
         string str2 = he.GetAttribute("format");
         if (!string.IsNullOrEmpty(str2))
         {
             int num2 = str2.LastIndexOf('.');
             decimals = (num2 >= 0) ? ((str2.Length - num2) - 1) : 0;
         }
     }
     return MathHelper.Round(Convert.ToDouble(attribute), decimals).ToString();
 }
 private static bool _IsItemLoading(HtmlElement el)
 {
     if (null == el) return false;
     string className = el.GetAttribute("className");
     return className.IndexOf("loading") > -1;
 }
Exemple #14
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            switch (step)
            {
                case 1:

                    step = 0;
                    toolStep.Text = "Étape : 1";
                    hotmailer.webBrowser1.Navigate("http://google.com");
                    hotmailer.Show();
                    step = 2;

                    break;

                case 2:

                    step = 0;
                    toolStep.Text = "Étape : 2";

                    identity = hotmailer.webBrowser1.Document.GetElementById("identity");

                    /*
                     * Modifications for GAF
                     *
                     */

                    SendKeys.Send("test");
                    ClearCookies();
                    WebBrowserHelper.ClearCache();
                    break;

                    if (identity != null)
                    {
                        // Entre mot de passe
                        identity.Focus();

                        SendKeys.Send("loubna");

                        if (identity.GetAttribute("value") != "loubna")
                        {
                            // La page n'était pas chargée
                            step = 2;
                            return;
                        }

                        // Entre code de campagne.
                        campaignCode = hotmailer.webBrowser1.Document.GetElementById("campaignCode");
                        campaignCode.Focus();

                        SendKeys.SendWait(codeDeCampagne);

                        while (campaignCode.GetAttribute("value") != codeDeCampagne)
                        {
                            campaignCode.Focus();

                            // Problème quelconque: on efface l'input et recommence.
                            while (campaignCode.GetAttribute("value") != "")
                            {
                                SendKeys.SendWait("{BACKSPACE}");
                            }

                            SendKeys.SendWait(codeDeCampagne);
                        }

                        // Clique sur une DIV invisble ayant onclick="next();": simule un "{ENTER}"
                        pressEnter = hotmailer.webBrowser1.Document.GetElementById("pressEnter");
                        pressEnter.InvokeMember("click");

                        step = 3;
                    }
                    else
                    {
                        step = 2;
                    }

                    break;

                case 3:

                    step = 0;
                    toolStep.Text = "Étape : 3";

                    // Collecte le compte Yahoo
                    address = hotmailer.webBrowser1.Document.GetElementById("address");
                    strAddress = address.GetAttribute("value");

                    if (strAddress == "")
                    {
                        // La page n'était pas chargée
                        step = 3;
                        return;
                    }

                    // Collecte le mot de passe
                    password = hotmailer.webBrowser1.Document.GetElementById("password");
                    strPassword = password.GetAttribute("value");

                    // Collecte le récipient
                    recipient = hotmailer.webBrowser1.Document.GetElementById("recipient");
                    strRecipient = recipient.GetAttribute("value");

                    // Collecte le sujet
                    subject = hotmailer.webBrowser1.Document.GetElementById("subject");
                    strSubject = subject.GetAttribute("value");

                    username = webBrowser1.Document.GetElementById("username");

                    if (username == null)
                    {
                        // Déjà loggé
                        hotmailer.Hide();
                        step = 6;
                    }
                    else
                    {
                        step = 4;
                    }

                    break;

                case 4:

                    step = 0;
                    toolStep.Text = "Étape : 4";
                    hotmailer.Hide();

                    // Injecte le nom de compte Yahoo
                    username = webBrowser1.Document.GetElementById("username");

                    if (username != null)
                    {
                        username.InvokeMember("focus");
                        SendKeys.SendWait(strAddress);

                        webBrowser1.Document.ExecCommand("SelectAll", true, null);
                        webBrowser1.Document.ExecCommand("Copy", true, null);

                        if (Clipboard.GetText() != strAddress)
                        {
                            // L'adresse n'a pas bien ete transmise
                            SendKeys.SendWait("^{BACKSPACE}");
                            step = 4;
                            break;
                        }
                        else
                        {
                            SendKeys.SendWait("{TAB}");

                            webBrowser1.Document.ExecCommand("SelectAll", true, null);
                            SendKeys.SendWait("^{BACKSPACE}");

                            // Injecte le mot de passe
                            passwd = webBrowser1.Document.GetElementById("passwd");
                            passwd.InvokeMember("focus");
                            SendKeys.SendWait(strPassword);

                            step = 5;
                        }
                    }
                    else
                    {
                        if (webBrowser1.Document.GetElementById("compose_button_label") != null)
                        {
                            // Login déjà fait. Page chargée.
                            step = 6;
                        }
                        else
                        {
                            step = 4;
                        }
                    }

                    break;

                case 5:

                    step = 0;
                    toolStep.Text = "Étape : 5";

                    loginCounter = 0;

                    webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    webBrowser1.Document.ExecCommand("Copy", true, null);

                    if (Clipboard.GetText() == strAddress || Clipboard.GetText().IndexOf("●") != -1)
                    {
                        // Nous sommes bien dans un input dans contenant l'adresse ou le mot de passe
                        SendKeys.SendWait("{ENTER}");
                        step = 6;
                    }
                    else
                    {
                        step = 4;
                    }

                    // Envoie la form (ID du bouton connection: ".save")
                    /*dotSave = webBrowser1.Document.GetElementById(".save");

                    if (dotSave != null)
                    {
                        dotSave.InvokeMember("click");
                        loginCounter = 0;
                        step = 6;
                    }
                    else
                    {
                        step = 5;
                    }*/

              break;

                case 6:

                    step = 0;
                    toolStep.Text = "Étape : 6";

                    if (webBrowser1.Document.GetElementById("compose_button_label") != null)
                    {
                        // Injecte N pour ouvrir l'onglet nouveau message
                        SendKeys.SendWait("n");

                        textAreas = webBrowser1.Document.GetElementsByTagName("textarea");
                        if (textAreas.Count < 3)
                        {
                            step = 6;
                        }
                        else
                        {
                            step = 7;
                        }
                    }
                    else
                    {
                        loginCounter++;

                        if (loginCounter >= 5)
                        {
                            // Apres 5 tentatives, re-login
                            step = 4;
                        }
                        else{
                            step = 6;
                        }
                    }

                    break;

                case 7:

                    step = 0;
                    toolStep.Text = "Étape : 7";

                    textAreas = null;
                    textAreas = webBrowser1.Document.GetElementsByTagName("textarea");

                    // Parcours tous les éléments TextArea pour trouver l'ID du champ "À:" (qui est aléatoire mais commence toujours par "Toi")
                    for (int i = 0; i <= textAreas.Count - 1; i++)
                    {
                        aID = textAreas[i].GetAttribute("id");
                        if (aID.Length > 3)
                        {
                            if (aID.Substring(0, 3) == "Toi")
                            {
                                aArea = webBrowser1.Document.GetElementById(aID);
                                aArea.InvokeMember("focus");
                                SendKeys.SendWait(strRecipient);

                                step = 8;
                                break;
                            }
                        }
                    }

                    break;

                case 8:

                    step = 0;
                    toolStep.Text = "Étape : 8";

                    // Vérifie que "À:" contient la bonne adresse
                    aArea = webBrowser1.Document.GetElementById(aID);
                    aArea.InvokeMember("focus");

                    webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    webBrowser1.Document.ExecCommand("Copy", true, null);
                    //webBrowser1.Document.ExecCommand("Unselect", true, null);

                    if (Clipboard.GetText() != strRecipient)
                    {
                        // Échec: input récipient vide ou incomplet
                        aArea.InvokeMember("focus");
                        SendKeys.SendWait(strRecipient);
                        step = 8;
                    }
                    else
                    {
                        step = 9;
                    }

                    break;

                case 9:

                    step = 0;
                    toolStep.Text = "Étape : 9";

                    // TAB à l'input "Sujet", au cas ou Focus() fail
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");

                    inputs = webBrowser1.Document.GetElementsByTagName("input");

                    // Parcours tous les éléments Input pour trouver l'ID du champ "Objet:" (qui est aléatoire mais commence toujours par "Subject")
                    for (int i = 0; i <= inputs.Count - 1; i++)
                    {
                        subjectID = inputs[i].GetAttribute("id");
                        if (subjectID.Length > 6)
                        {
                            if (subjectID.Substring(0, 7) == "Subject")
                            {
                                input = webBrowser1.Document.GetElementById(subjectID);
                                input.InvokeMember("focus");
                                SendKeys.SendWait(strSubject);
                                step = 10;
                                break;
                            }
                        }
                    }

                    break;

                case 10:

                    step = 0;
                    toolStep.Text = "Étape : 10";

                    // Vérifie que "Objet:" contient le bon message
                    input = webBrowser1.Document.GetElementById(subjectID);
                    input.InvokeMember("focus");

                    webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    webBrowser1.Document.ExecCommand("Copy", true, null);
                    //webBrowser1.Document.ExecCommand("Unselect", true, null);

                    if (Clipboard.GetText() != strSubject)
                    {
                        // Échec: input sujet vide ou incomplet
                        input.InvokeMember("focus");
                        SendKeys.SendWait(strSubject);
                        step = 10;
                    }
                    else
                    {
                        // Tab à la textArea du message
                        SendKeys.SendWait("{TAB}");

                        hotmailer.Show();
                        step = 11;
                    }

                    break;

                case 11:

                    step = 0;
                    toolStep.Text = "Étape : 11";

                    // Focus sur l'IFRAME.
                    subject = hotmailer.webBrowser1.Document.GetElementById("subject");
                    subject.Focus();
                    SendKeys.SendWait("{TAB}");

                    // Vide le clipboard
                    Clipboard.Clear();

                    // CTRL + A, CTRL + C pour transférer le message au clipboard
                    hotmailer.webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    hotmailer.webBrowser1.Document.ExecCommand("Copy", true, null);

                    if (Clipboard.GetText().IndexOf("Si vous souhaitez ne plus recevoir cette newsletter") == -1)
                    {
                        // Échec: IFRAME non chargé, clipboard vide ou incomplet
                        step = 11;
                    }
                    else
                    {
                        hotmailer.webBrowser1.Document.ExecCommand("Unselect", true, null);

                        hotmailer.Hide();
                        step = 12;
                    }

                    break;

                case 12:

                    step = 0;
                    toolStep.Text = "Étape : 12";

                    // Injecte le message
                    webBrowser1.Document.ExecCommand("Paste", true, null);

                    // Vérifie que le champ du message n'est pas vide
                    /*input = webBrowser1.Document.GetElementById(subjectID);
                    input.InvokeMember("focus");*/
                    SendKeys.SendWait("{TAB}");

                    webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    webBrowser1.Document.ExecCommand("Copy", true, null);
                    webBrowser1.Document.ExecCommand("Unselect", true, null);

                    if (Clipboard.GetText().IndexOf("Si vous souhaitez ne plus recevoir cette newsletter") == -1)
                    {
                        // Échec: message absent ou incomplet
                        step = 12;
                    }
                    else
                    {
                        // Remonte à "Cc:"
                        SendKeys.SendWait("+{TAB}");
                        SendKeys.SendWait("+{TAB}");
                        // Injecte un espace dans "Cc:" pour pouvoir vérifier s'il ne contient que cela (s'il est vide, CTRL+A CTRL+C ne l'indique pas)
                        SendKeys.SendWait(" ");

                        step = 13;
                    }

                    break;

                case 13:

                    step = 0;
                    toolStep.Text = "Étape : 13";

                    isCcEmpty();

                    // Remonte à "À:" (SHIT+TAB) au cas où focus fail
                    SendKeys.SendWait("+{TAB}");

                    step = 14;

                    break;

                case 14:

                    step = 0;
                    toolStep.Text = "Étape : 14";

                    isRecipientValid();

                    // Descend à "Sujet:" (TAB) au cas où focus fail
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");

                    step = 15;

                    break;

                case 15:

                    step = 0;
                    toolStep.Text = "Étape : 15";
                    isSubjectValid();
                    step = 16;

                    break;

                case 16:

                    step = 0;
                    toolStep.Text = "Étape : 16";

                    // Envoie le message (CTRL + ENTER)
                    SendKeys.SendWait("^{ENTER}");

                    // Clique a une certaine coordonnée, là où le message de bienvenue de Yahoo peut apparaître
                    //clickOnWebBrowser(535, 450);

                    step = 17;

                    break;

                case 17:

                    step = 0;

                    captchaCounter = 0;
                    toolStep.Text = "Étape : 17";

                    // Vérification de captcha
                    // Si 3 inputs ont comme ID "firstName[...]", le message est envoyé.

                    messageSent = webBrowser1.Document.GetElementsByTagName("input");

                    for (int i = 0; i <= messageSent.Count - 1; i++)
                    {
                        messageSentID = messageSent[i].GetAttribute("id");

                        if (messageSentID.IndexOf("firstName") != -1)
                        {
                            captchaCounter++;
                        }

                        if (messageSentID.IndexOf("captcha_resp") != -1)
                        {
                            // Captcha!
                            step = 19;
                            goto Fin;
                        }
                    }

                    if (captchaCounter >= 3)
                    {
                        // Message envoyé, ferme l'onglet (CTRL+BACKSPACE)
                        step = 18;
                        SendKeys.Send("^{BACKSPACE}");
                    }
                    else
                    {
                        // "Envoi du message..."
                        step = 17;
                    }

            Fin:

                    break;

                case 18:

                    step = 0;
                    toolStep.Text = "Étape : 18";

                    // Génère prochain mail.
                    pressEnter = hotmailer.webBrowser1.Document.GetElementById("pressEnter");

                    if (pressEnter != null)
                    {
                        hotmailer.Show();
                        pressEnter.InvokeMember("click");

                        step = 20;
                    }
                    else
                    {
                        step = 18;
                    }

                    break;

                case 19:

                    step = 0;
                    toolStep.Text = "Étape : 19";

                    // Reset le compteur de /tool
                    pressEscape = hotmailer.webBrowser1.Document.GetElementById("pressEscape");

                    if (pressEscape != null)
                    {
                        hotmailer.Show();
                        pressEscape.InvokeMember("click");

                        // Génère un nouveau compte Yahoo
                        pressEnter.InvokeMember("click");

                        step = 20;
                    }
                    else
                    {
                        step = 19;
                    }

                    break;

                case 20:

                    step = 0;
                    toolStep.Text = "Étape : 20";

                    // Attend que le récipient ai changé (page chargée)
                    recipient = hotmailer.webBrowser1.Document.GetElementById("recipient");

                    string tmpRecipient = recipient.GetAttribute("value");

                    if (tmpRecipient != strRecipient && tmpRecipient != null && tmpRecipient != "")
                    {
                        //iteration++;

                        address = hotmailer.webBrowser1.Document.GetElementById("address");

                        string tmpAddress = address.GetAttribute("value");

                        if (tmpAddress != strAddress)
                        {
                            iteration++;

                            strAddress = tmpAddress;
                            strRecipient = tmpRecipient;

                            // Collecte le mot de passe
                            password = hotmailer.webBrowser1.Document.GetElementById("password");
                            strPassword = password.GetAttribute("value");

                            // Efface les cookies
                            ClearCookies();

                            // Efface le cache
                            WebBrowserHelper.ClearCache();

                            // Ferme la session
                            InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);

                            // Rafraîchit la page
                            webBrowser1.Document.Window.Navigate("http://login.yahoo.com/config/login_verify2?.intl=fr&.src=ym");
                            //webBrowser1.Document.Window.Navigate("http://mail.yahoo.fr");

                            step = 4;
                        }
                        else
                        {
                            hotmailer.Hide();
                            strRecipient = tmpRecipient;

                            step = 6;
                            //iteration++;
                        }
                    }
                    else
                    {
                        step = 20;
                    }

                    break;
            }
        }
        private void NavigateToAsHref(HtmlElement navigateAElem)
        {
            var href = navigateAElem.GetAttribute("href");

            var url = href;
            webBrowser1.Navigate(url);
        }
Exemple #16
0
		bool GetInfoForResult(HtmlElement element, out string file, out int line, out int startChar, out int endChar)
		{
			file = element.GetAttribute("myFile");
			line = Int32.Parse(element.GetAttribute("myLine"));
			startChar = Int32.Parse(element.GetAttribute("myStartChar"));
			endChar = Int32.Parse(element.GetAttribute("myEndChar"));

			return file != "";
		}
Exemple #17
0
 public HtmlPassword(HtmlElement element)
     : base(element.Id)
 {
     Value = element.GetAttribute("value");
 }
Exemple #18
0
 private string GetXpathId(HtmlElement ele)
 {
     string id = ele.GetAttribute("id");
     if (String.IsNullOrEmpty(id) == false)
     {
         HtmlElement tmpEle = ele.Document.GetElementById(id);
         if (ele.Equals(tmpEle)) return id;
     }
     return null;
 }
Exemple #19
0
            public override bool Match(HtmlElement element)
            {
                var attr = element.GetAttribute(AttributeName);

                return(!string.IsNullOrEmpty(attr));
            }
Exemple #20
0
        private HtmlElement FindClassRecusive(HtmlElement element, string className)
        {
            if (element == null)
            {
                return null;
            }

            string elementClassName = element.GetAttribute("className");
            if (wholeWordRegex.Match(elementClassName).Success)
            {
                return element;
            }

            if (element.Children != null && element.Children.Count > 0)
            {
                foreach (HtmlElement child in element.Children)
                {
                    HtmlElement find = FindClassRecusive(child, className);
                    if (find != null)
                    {
                        return find;
                    }
                }
            }

            return null;
        }
 private static double? UseGetDataCalc(HtmlDocument doc, DataSet ds, HtmlElement field, Dictionary<string, InvokeResult> invokes)
 {
     string attribute = field.GetAttribute("getdata_1");
     double? nullable = null;
     int num = 1;
     while (!string.IsNullOrEmpty(attribute))
     {
         double num2;
         if (double.TryParse(ParseGetData(doc, field.GetAttribute("dbcolumn"), ds, attribute, invokes), out num2))
         {
             nullable = new double?(nullable.HasValue ? (nullable.Value * num2) : num2);
         }
         num++;
         attribute = field.GetAttribute(string.Format("getdata_{0}", num));
     }
     return nullable;
 }
 private static void SetHtmlElementValue(HtmlDocument doc, DataSet ds, HtmlElement he, Dictionary<string, InvokeResult> invokes)
 {
     string attribute = he.GetAttribute("ref");
     if ((attribute != null) && (attribute.Trim().Length > 0))
     {
         HtmlElement elementById = doc.GetElementById(attribute);
         if (elementById != null)
         {
             double? nullable = HtmlElementCalc(doc, elementById, invokes);
             SetHtmlElementValue(he, nullable.HasValue ? MathHelper.Round(nullable.Value, 2).ToString("0.00") : string.Empty);
         }
     }
     else
     {
         string getdata = he.GetAttribute("getdata").Trim().Replace("\r", "").Replace("\n", "");
         if ((getdata != null) && (getdata.Length > 0))
         {
             SetHtmlElementValue(he, ParseGetData(doc, he.GetAttribute("dbcolumn"), ds, getdata, invokes));
         }
     }
 }
 private static double? HtmlElementCalc(HtmlDocument doc, HtmlElement field, Dictionary<string, InvokeResult> invokes)
 {
     string attribute = field.GetAttribute("invoke");
     if (!string.IsNullOrEmpty(attribute))
     {
         if ((invokes != null) && invokes.ContainsKey(attribute))
         {
             return invokes[attribute](field.GetAttribute("params"));
         }
         if (attribute != "qj")
         {
             throw new ApplicationException(string.Format("没有找到计算{0}值的方法:{1}", field.Id, attribute));
         }
         return QJCalc(doc, field.GetAttribute("params"));
     }
     return SimpleMultiCalc(doc, field.Id);
 }
 public static void SetHtmlElementValue(HtmlElement he, string value)
 {
     LoggingService.DebugFormatted("将设置{0}-{1}的值:{2}", new object[] { he.Document.Url.ToString(), he.Id, value });
     he.SetAttribute("value", value);
     if (he.TagName.ToLower() == "select")
     {
         string attribute = he.GetAttribute("valuechange");
         if ((attribute != null) && (attribute.Length > 0))
         {
             he.Document.InvokeScript(attribute, new string[] { value });
         }
     }
 }
    private IDictionary<string, string> GetRelevantAttributes (HtmlElement element)
    {
      var dict = new Dictionary<string, string> (s_attributes.Length);
      foreach (var attributeName in s_attributes)
        dict.Add (attributeName, element.GetAttribute (attributeName));

      return dict;
    }
Exemple #26
0
 public HtmlText(HtmlElement element)
     : base(element.Id)
 {
     Value = element.GetAttribute("value");
 }
Exemple #27
0
        protected void GoToNextPage(HtmlElement oLink, ref WebBrowser oBrowser)
        {
            CountedWait oCWTimer = new CountedWait(ref oBrowser, 3000);
            while (true)
            {
                try
                {
                    // Below line added to rise UnauthorizedAccessException in case something went wrong
                    String sHREF = oLink.GetAttribute("href");

                    oLink.InvokeMember("click");
                    if (oCWTimer.Wait(10))
                    {
                        TimedWait oTimedWait = new TimedWait(oRandomizer.Next(8000, 14000));
                        oTimedWait.Wait();
                        return;
                    }
                    else
                    {
                        //System.Console.WriteLine("Proxy timeout, switching to next one.");
                        wininet.RefreshIEProxySettings();
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                    throw new UnauthorizedAccessException("Unauthorized access to HTML properties, aborting operation", ex);
                }
                catch (AccessViolationException ex)
                {
                    throw new AccessViolationException("Access Violation, aborting operation", ex);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("..::" + this.GetType().Name + "::..GoToNextPage thrown an exception, reason:  " + ex.Message + ", switching proxy");
                    wininet.RefreshIEProxySettings();
                }
            }
        }
Exemple #28
0
        protected void UpdateUrlAbsolute(HtmlElement ele)
        {
            HtmlElementCollection eleColec = ele.GetElementsByTagName("IMG");
            foreach (HtmlElement it in eleColec)
            {
                it.SetAttribute("src", it.GetAttribute("src"));
            }
            eleColec = ele.GetElementsByTagName("A");
            foreach (HtmlElement it in eleColec)
            {
                it.SetAttribute("href", it.GetAttribute("href"));
            }

            if (ele.TagName == "A")
            {
                ele.SetAttribute("href", ele.GetAttribute("href"));
            }
            else if (ele.TagName == "IMG")
            {
                ele.SetAttribute("src", ele.GetAttribute("src"));
            }
        }
Exemple #29
0
 protected void NavigateToSite(HtmlElement oLink, ref WebBrowser oBrowser)
 {
     CountedWait oCWTimer = new CountedWait(ref oBrowser, 3000);
     while (true)
     {
         try
         {
             sSiteToNavigate = oLink.GetAttribute("href");
             oLink.InvokeMember("click");
             if (oCWTimer.Wait(10))
             {
                 bSiteFound = true;
                 TimedWait oTimedWait = new TimedWait(oRandomizer.Next(10000, 30000));
                 oTimedWait.Wait();
                 return;
             }
             else
             {
                 //System.Console.WriteLine("Proxy timeout, switching to next one.");
                 wininet.RefreshIEProxySettings();
             }
         }
         catch (UnauthorizedAccessException ex)
         {
             throw new UnauthorizedAccessException("..::" + this.GetType().Name + "::..NavigateToSite thrown an exception", ex);
         }
         catch (AccessViolationException ex)
         {
             throw new AccessViolationException("..::" + this.GetType().Name + "::..NavigateToSite thrown an exception", ex);
         }
         catch (Exception ex)
         {
             System.Console.WriteLine("..::" + this.GetType().Name + "::..NavigateToSite thrown an exception, reason:  " + ex.Message + ", switching proxy");
             wininet.RefreshIEProxySettings();
         }
     }
 }
Exemple #30
0
 public override bool Match(HtmlElement element)
 {
     return(element.GetAttribute("id") == IdAttributeValue);
 }
        private static void Navigate(HtmlElement hel)
        {
            var ans = EditorObserver.ActiveEditor.GetElementsByTagName(TagNames.AnchorTagName);
            foreach (HtmlElement he in ans)
            {
                if (he.Id != null)
                {
                    if (he.Id.Equals(TrainingModuleXmlWriter.ExtractRelativeHref(hel.GetAttribute("href"))))
                    {
                        try
                        {
                            EditorObserver.ActiveEditor.ScrollToHtmlElement(he);
                        }
                        catch (Exception exception)
                        {
                            ExceptionManager.Instance.LogException(exception);
                        }

                        EditorObserver.ActiveEditor.HighlightedElement = he;

                        try
                        {
                            EditorObserver.ActiveEditor.Highlight(he, true);
                        }
                        catch (Exception exception)
                        {
                            ExceptionManager.Instance.LogException(exception);
                        }

                        break;
                    }
                }
            }
        }
 private static HtmlElement GetElementByName(HtmlElement root, string elementName)
 {
     HtmlElement result = null;
     if (root != null)
     {
         if (root.GetAttribute("name") != null && root.GetAttribute("name") == elementName)
         {
             return root;
         }
         else
         {
             if (root.Children != null)
             {
                 foreach (HtmlElement el in root.Children)
                 {
                     result = GetElementByName(el, elementName);
                     if (result != null)
                     {
                         break;
                     }
                 }
             }
         }
     }
     return result;
 }
Exemple #33
0
 public override bool Match(HtmlElement element)
 {
     return(element.GetAttribute("className").Split(' ').Any(x => x == ClassAttributeValue));
 }