コード例 #1
0
        async Task PopulateInputFile(HtmlElement file, String photo)
        {
            file.Focus();

            // delay the execution of SendKey to let the Choose File dialog show up
            var sendKeyTask = TaskEx.Delay(500).ContinueWith((_) =>
            {
                // this gets executed when the dialog is visible
                SendKeys.SendWait(photo + "{ENTER}");
            }, TaskScheduler.FromCurrentSynchronizationContext());

            file.InvokeMember("Click"); // this shows up the dialog

            await sendKeyTask;
            file.RemoveFocus();

            // delay continuation to let the Choose File dialog hide
            await TaskEx.Delay(500);
        }
コード例 #2
0
ファイル: Macro.cs プロジェクト: blorenz/seocortex
        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;
            }
        }
コード例 #3
0
ファイル: ClickTask.cs プロジェクト: pisceanfoot/xSimulate
 public void Focus(HtmlElement h)
 {
     h.Focus();
 }
コード例 #4
0
ファイル: BrowserBot.cs プロジェクト: Alister742/ParseKit
 public void Focus(HtmlElement elem)
 {
     elem.Focus();
 }
コード例 #5
0
ファイル: Registor.cs プロジェクト: bodhifan/BoRegister
 private void InputValue(HtmlElement element, string value)
 {
     element.SetAttribute("value", value);
     webBrowser.Select();
     webBrowser.Focus();
     element.Focus();
     System.Windows.Forms.SendKeys.Send("{tab}");
     System.Windows.Forms.SendKeys.Send(" ");
 }